使用某服务商的webservice服务,其wsdl里有个这样一个变量:
<<wsdl:part name="mobiles" type="impl:ArrayOf_xsd_string" />
而php里并没有对应的类型。
使用
$mobiles = '18900000000';
$mobiles[0]='18900000000';
甚至mobiles[0][0]='18900000000';
都不行,会提示:
Fatal error: Uncaught SoapFault exception: [soapenv:Server.userException] org.xml.sax.SAXException: No deserializer defined for array type {http://www.w3.org/2001/XMLSchema}string in /www/9enjoy.com/include/hx.php:46 Stack trace: #0 /www/9enjoy.com/include/hx.php(46): SoapClient->__call('sendSM', Array) #1 /www/9enjoy.com/include/hx.php(2): send_mobile('18900000000', '{????????}?????...') #2 {main} thrown in /www/9enjoy.com/include/hx.php on line 46
使用.NET WebService Studio工具测试,将参数填入后,得到request的xml为:
<q1:sendSM>
<mobiles href="#id1" />
<content xsi:type="xsd:string">test</content>
...
</qi:sendSM>
<soapenc:Array id="id1" soapenc:arrayType="xsd:string[1]">
<Item>18900000000</Item>
</soapenc:Array>
测试多次后发现有两种解决办法:
1.较简单,把ArrayOf_xsd_string这种格式转换为数组格式
<?php
$client = new SoapClient("some.wsdl", array('features' => SOAP_USE_XSI_ARRAY_TYPE));
?>
这时,可使用$mobiles = array('18900000000');来传递$mobiles变量。
这是php5.2.2起增加的功能
. Added ability to encode arrays with "SOAP-ENC:Array" type instead of WSDL
type. To activate the ability use "feature"=>SOAP_USE_XSI_ARRAY_TYPE
option in SoapClient/SoapServer constructors. (Rob, Dmitry)
2.将整个xml文档用doRequest 方法发送出去
public string SoapClient::__doRequest ( string $request , string $location , string $action , int $version [, int $one_way = 0 ] )
http://www.9enjoy.com/no-deserializer-defined-for-array-type/