简体   繁体   English

如何为带有项目列表的肥皂响应定义WSDL复杂类型

[英]How to define WSDL complex type for soap response with list of items

I`m creating a web service using php soapServer/soapClient class with wsdl. 我正在使用wsdl使用php soapServer / soapClient类创建Web服务。 There are some services, which should return list of items. 有一些服务,应该返回项目列表。 Service returns something like this: 服务返回如下内容:

<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>

But I need to name all elements by attribut name. 但是我需要通过属性名称来命名所有元素。 So something like this: 所以像这样:

<result>
  <item>
    <attr1>value1</attr1>
    <attr2>value2</attr2>
    ....
  </item>
  <item>
    ...
  </item>
</result>

The structure of returned array is: 返回数组的结构为:

'result' => array
  0 => array
      'attr1' => 'value1'
      'attr2' => 'value2'
      ...
  1 => array
      ...
  ...

EDIT My WSDL: 编辑我的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>

Port Type: 端口类型:

<operation name="getTransactions">
  <input message="tns:getTransactionsRequest" />
  <output message="tns:getransactionsResponse" />
</operation>

Binding: 捆绑:

<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>

I dont know, if I was googling bad, but I could`t find any solution. 我不知道,如果我谷歌搜索不好,但是我找不到任何解决方案。 So I would be glad for some simple example, link to tutorial or documentation, how wsdl should look. 因此,对于一些简单的示例(链接到教程或文档)以及wsdl的外观,我感到很高兴。 Or I have to change hole structure of my array? 还是我必须更改阵列的孔结构? Im looking for best practice, how to prepare response as array of items on server side and its wsdl definition. 我正在寻找最佳实践,即如何在服务器端及其wsdl定义中将响应准备为项目数组。

Problem solved. 问题解决了。 I just transfer my response array into object and now I get expected soap response form like in my question. 我只是将我的响应数组转换为对象,现在我得到了预期的肥皂响应表,就像我的问题一样。 Dont know why, but it works. 不知道为什么,但是它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM