简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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