[英]How to define WSDL complex type for soap response with list of items
我正在使用wsdl使用php soapServer / soapClient类创建Web服务。 有一些服务,应该返回项目列表。 服务返回如下内容:
<SOAP-ENV:Envelope ...>
<SOAP-ENV:Body>
<ns1:getTransactionsResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">result</key>
<value SOAP-ENC:arrayType="ns2:Map[65]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">id</key>
<value xsi:type="xsd:int">283</value>
</item>
<item>
...
</item>
...
</item>
</item>
</return>
</ns1:getItemsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但是我需要通过属性名称来命名所有元素。 所以像这样:
<result>
<item>
<attr1>value1</attr1>
<attr2>value2</attr2>
....
</item>
<item>
...
</item>
</result>
返回数组的结构为:
'result' => array
0 => array
'attr1' => 'value1'
'attr2' => 'value2'
...
1 => array
...
...
编辑我的WSDL:
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:XYZ">
<xsd:complexType name="Properties">
<xsd:sequence>
<xsd:element name="attr1" type="xsd:int"/>
<xsd:element name="attr2" type="xsd:string"/>
...
</xsd:sequence>
</xsd:complexType>
<xsd:element name="transactionsResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="result" nillable="true" type="tns:Properties"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</types>
<message name="getTransactionsResponse">
<part name="parameters" type="tns:transactionsResponse" />
</message>
端口类型:
<operation name="getTransactions">
<input message="tns:getTransactionsRequest" />
<output message="tns:getransactionsResponse" />
</operation>
捆绑:
<operation name="getVirtualTransactions">
<soap:operation soapAction="urn:getTransactionsAction" />
<input>
<soap:body use="encoded" namespace="urn:XYZ" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:XYZ" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
我不知道,如果我谷歌搜索不好,但是我找不到任何解决方案。 因此,对于一些简单的示例(链接到教程或文档)以及wsdl的外观,我感到很高兴。 还是我必须更改阵列的孔结构? 我正在寻找最佳实践,即如何在服务器端及其wsdl定义中将响应准备为项目数组。
问题解决了。 我只是将我的响应数组转换为对象,现在我得到了预期的肥皂响应表,就像我的问题一样。 不知道为什么,但是它有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.