Getting data from a WSDL web service in PHP

I will start by saying that I have no idea what I have ever done. My PHP skills are -beginner- and my experience with web services is NULL.

I have a WSDL URL http://example.com/ws/3.1/NNE?WSDL . I would like to call the searchTargetGroup method from a PHP script, so I can execute a response loop and save the data in my database.

Anywho, I have no idea how to create a call with PHP. :-( I looked at NuSOAP for PHP, as well as the built-in SoapClient, but with no luck. I think the problem is that I'm trying to name a complex method, not up to end of understanding what I'm frog with.

So, I used SoapUI to extract the definition file and create a query that works fine, and I get all the necessary information. The problem is that I have no clue , how should I make a PHP file that creates the same request as SoapUI (and thereby get the correct answer).

The XML SoapUI request for me is as follows:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nne="http://example.com/ws/NNE"> <soapenv:Header/> <soapenv:Body> <nne:searchTargetGroup soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <QuestionTargetGroup_1 xsi:type="nne:QuestionTargetGroup" xmlns:nne="http://example.com/ws/NNE"> <companyFormCodeList xsi:type="xsd:string">10,60,80</companyFormCodeList> <companyStatus xsi:type="xsd:string">0</companyStatus> <hasPhoneOnly xsi:type="xsd:boolean">true</hasPhoneOnly> </QuestionTargetGroup_1> <int_2 xsi:type="xsd:int">500</int_2> <int_3 xsi:type="xsd:int">1</int_3> <int_4 xsi:type="xsd:int">1</int_4> <String_5 xsi:type="xsd:string">passstring</String_5> </nne:searchTargetGroup> </soapenv:Body> </soapenv:Envelope> 

Can someone help me in a certain direction? Preferably correct. :-)

I know that you cannot test the URL since it is protected by IP address, but I would just like to know how to make the above call from the PHP file / function.

+4
source share
3 answers

First of all, I start here, so I cannot guarantee a completely correct answer, but I can give you at least some clues.

Use SoapClient instead of NuSoap. SoapClient is written in C, NuSoap in PHP, so SoapClient is faster.

If your WSDL file is fine, then all you need to do should be:

 $client = new SoapClient("[URL to wsdl]"); 

After that, SoapClient will take care of the rest and make all the procedures defined in the WSDL available directly.

 $result = $client->name_of_procedure($arg1, $arg2, ...); 

The result will be of type stdClass or an array with elements of type stdClass.

Without WSDL, you will need to specify all the details yourself, type of parameters, namespace, ... and call via __ soapCall () directly.

In any case, you can check the structure of $ result with var_dump () and Co.

+3
source

As Raffael said, you better use the SoapClient offered by PHP SOAP EXTENSION.

To check your service:

first declare an array of options where you can say, for example, do not interrupt wsdl (it is useful in the development environment)

 $options = array( 'soap_version'=>SOAP_1_1, 'exceptions'=>true, 'trace'=>1, 'cache_wsdl'=>WSDL_CACHE_NONE ); 

then create a client starting with wsdl, which you have:

 $client = new SoapClient("http://service.nnerhverv.dk/nne-ws/3.1/NNE?WSDL", $options); 

call the searchTargetGroup method as follows. Here you need to build the questionTargetGroup parameter correctly, this should work:

 //build the parameters for the SearchTargetGroup $questionTargetGroup = array ( "companyFormCodeList" => "10,60,80", "companyStatus" => "0", "hasPhoneOnly" => "true" ); $response = $client->searchTargetGroup($questionTargetGroup, 500, 1, 1, "passstring"); 

finally print the answer you received from the service

 print_r($response); 
+1
source

I wrote an article on how to call Serena web services from PHP. But it can work for any web services: http://www.geekmindsthinkalike.com/php-and-serena-web-services/

Hope this helps

0
source

All Articles