PHP SoapClient调用含属性的SOAP接口时出现属性解析错误的问题咨询
PHP SoapClient调用含属性的SOAP接口时出现属性解析错误的问题咨询
我在使用PHP的SoapClient调用一个SOAP接口时遇到了参数格式相关的问题,折腾了很久没解决,想请教下大家。
接口要求的XML参数结构
首先,目标接口的WSDL要求的请求Body结构如下:
<soapenv:Body> <cai3:Set> <cai3:MOId> <gsm:param1>?</gsm:param1> </cai3:MOId> <cai3:MOAttributes> <gsm:setSubscription a="?"> <gsm:custId>?</gsm:custId> </gsm:setSubscription> </cai3:MOAttributes> </cai3:Set> </soapenv:Body>
我编写的PHP调用代码
根据这个结构,我写了如下的PHP代码:
$params = array( 'MOId' => array ( 'param1' => "test1", ), 'MOAttributes' => array ( 'setSubscription a=123' => array ( 'custId' => '123456' ) ) ); $client = new SoapClient ($wsdl, array( 'location' => "http://$ip:8080/services/CAI3G1.2", 'uri' => "http://$ip:8080/services/CAI3G1.2", 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'connection_timeout' => 5, 'trace' => 1, 'encoding' => 'UTF-8' )); try { $response = $client->Set($params); } catch(Exception $e){ if ($debug) print_r($e); return $e; }
遇到的错误信息
执行这段代码后,抛出了如下的SOAP错误:
[faultstring] => SOAP-ERROR: Encoding: object has no 'setSubscription' property
奇怪的对比结果
但是我用SoapClient发送了完全相同逻辑的请求(如下XML),接口却能正常响应,没有任何错误:
<soapenv:Body> <cai3:Set> <cai3:MOId> <gsm:param1>test1</gsm:param1> </cai3:MOId> <cai3:MOAttributes> <gsm:setSubscription a="123"> <gsm:custId>123456</gsm:custId> </gsm:setSubscription> </cai3:MOAttributes> </cai3:Set> </soapenv:Body>
我的疑问
从错误信息来看,SoapClient似乎没有识别到setSubscription这个对象,我怀疑是不是因为我把属性a=123直接拼在了键名里(也就是'setSubscription a=123'这个键),导致SoapClient无法解析成正确的XML元素?或者是编码的问题?有没有正确的参数数组写法来处理这种带属性的XML元素?
内容来源于stack exchange
相关产品推荐
相关产品推荐

