簡體   English   中英

如何為帶有項目列表的肥皂響應定義WSDL復雜類型

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM