我有一个 Web 服务函数,它将一组项目返回给 PHP 客户端。根据项目的数量,PHP 返回类型有所不同。如果函数返回一项,则 PHP 类型为stdClass
如果函数返回多个项目,则 PHP 类型为array
。无论哪种情况都应该是array
。我可以做什么来实现这个目标?
Details:
A
var_dump
of the result from the web-service function looks like following:
- 如果结果中有一项:
array(3) { ["filterErg"]=> object(stdClass)#37 (1) { ["item"]=> object(stdClass)#38 (9) ...
- 如果结果中包含多个项目:
array(3) { ["filterErg"]=> object(stdClass)#37 (1) { ["item"]=> array(16) ...
函数的名称是getFilter
WSDL 文件的相关部分是:
<types>
<schema ...>
<complexType name="arrayFilter">
<sequence>
<element name="item" type="ns1:stFilter" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
</sequence>
</complexType>
...
</schema>
</types>
<message name="getFilterResponse">
<part name="filterErg" type="ns1:arrayFilter"/>
<part name="functionResult" type="xsd:int"/>
<part name="outErr" type="xsd:string"/>
</message>
<portType name="ADServicePortType">
<operation name="getFilter">
<documentation>Service definition of function ns1__getFilter</documentation>
<input message="tns:getFilter"/>
<output message="tns:getFilterResponse"/>
</operation>
...
</portType>
<binding name="ADService" type="tns:ADServicePortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getFilter">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:ADService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:ADService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
...
</binding>
创建 SoapClient 时可以使用 SOAP_SINGLE_ELEMENT_ARRAYS 选项
$soapConfig = array(
'soap_version' => SOAP_1_2,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true
);
$client = new SoapClient('http://localhost:8070/Services.wsdl', $soapConfig);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)