PHP SoapClient malformed xml

只谈情不闲聊 提交于 2021-02-20 09:10:02

问题


I'm communicating with a webservice in SOAP with php. Here's 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 wrong :

<?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 come the XML node name is paramX when it should be the variable name ? What am i doing wrong ??

Thanks

Update : So I've listed the functions from that webservice and what I get is :

Some_Service_Response Some_Service(Some_Service $parameters))

I changed my call so it is 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 on my end ?


回答1:


If I were you I'd try setting up $data in an object format.

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

For example:

$data = null;
$data->name = "test";
$data->age = 20;

$RESULT = $SOAP->__soapCall('Some_Service', $data);



回答2:


The SoapClient class makes many corrections based on the WSDL of the service, e.g. removes invalid tags. Check the WSDL, it may contain that the name of the parameters are param1 and param2.

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


(After the OP updated the question that of the output of SoapClient::__getFunctions() is:

Some_Service_Response Some_Service(Some_Service $parameters))

)

Usually the array key is the parameter name, not the type. So my first guess would be:

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

The problem may be on the server-side though. WSDL incompatibilities sometimes require hand-tuning of the WSDL files so that PHP emits the same XML that you want.

But before doing any hacking (if you have the chance) be sure to try out the service without PHP to see the reaction of the service to different XML files. A nice program called SoapUI can do this for you, it automatically generates XML stubs to test. (I only had problems with SoapUI with web services that needed digital signatures.)

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

  • Hand-tune the WSDL
  • Generate the XML file by hand and send that to the web server (last resort)
  • If the XML is almost correct, it just needs a small fine tuning you can also derive from the SoapClient class and override the SoapClient::__doRequest method to do string manipulations on the XML file before submitting to the server (by calling the __dorequest of the base class). One example, when I used this solution when the web service required some XML attributes to be resent on some tags.


来源:https://stackoverflow.com/questions/14363147/php-soapclient-malformed-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!