PHP SoapClient Distorted xml

I communicate with webservice in SOAP with php. Here is my code:

$data = array('name' => 'test', 'age' => 20); $WDSL = 'http://xxx.xxxxx.xxx/wdsl.ibs?wsdl'; $SOAP = new SoapClient($WDSL, array('trace' => true)); $RESULT = $SOAP->__soapCall('Some_Service', $data); 

For some reason, the XML is incorrect:

 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Some_Crap"><SOAP-ENV:Body><ns1:Some_Service/><param1>test</param1><param2>20</param2> ... 

How did the XML name paramX come about when it should be the name of the variable? What am I doing wrong?

thanks

Update: Therefore, I have listed the functions from this web service, and I get:

 Some_Service_Response Some_Service(Some_Service $parameters)) 

I changed my call so that it now:

 $SOAP->__call('Some_Service', array('Some_Service', $data)); 

And the XML is still wrong:

 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:iwaysoftware:ibse:jul2003:HR_Master"><SOAP-ENV:Body><ns1:Some_Service/> <param1><item><key>SomeKey</key><value>SomeValue</value> .... 

I still get <param1><item><key>SomeKey</key><value>SomeValue</value> instead of <Somekey>SomeValue</Somekey>

So the question is, is the web service not working properly or is it at my end?

+6
source share
2 answers

If I were you, I would try to set up $ data in an object format.

 $data = array('name' => 'test', 'age' => 20); 

For instance:

 $data = null; $data->name = "test"; $data->age = 20; $RESULT = $SOAP->__soapCall('Some_Service', $data); 
+4
source

The SoapClient class makes many corrections based on the WSDL service, for example. removes invalid tags. Check the WSDL, it may contain that the parameter name is param1 and param2 .

Calling SoapClient::__getFunctions() and SoapClient::__getTypes() and dumping the results gives a pretty good summary of what PHP understood from your WSDL.


(After updating the OP, the question is what is the output of SoapClient::__getFunctions() :

 Some_Service_Response Some_Service(Some_Service $parameters)) 

)

Typically, an array key is a parameter name, not a type. Therefore, I assume the following:

 $SOAP->__call('Some_Service', array('parameters', $data)); 

The problem may be server side. WSDL incompatibility sometimes requires manual configuration of WSDL files, so PHP emits the same XML that you want.

But before you make any hacks (if you have a chance), be sure to try the service without PHP to see the reaction of the service to different XML files. A good program called SoapUI can do this for you; it automatically generates XML stubs for testing. (I had problems with SoapUI with web services that need digital signatures.)

Based on the results of XML testing, you may need to:

  • Manual WSDL
  • Create the XML file manually and send it to the web server (as a last resort)
  • If the XML is almost correct, it just needs a little tweaking, which you can also get from the SoapClient class and override the SoapClient::__doRequest to perform string manipulations in the XML file before sending it to the server (by calling the __dorequest base class). For example, when I used this solution, when the web service required some XML attributes to be re-sent to some tags.
+7
source

All Articles