本文介绍了如何使用项目列表为soap响应定义WSDL复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 wsdl 的 php soapServer/soapClient 类创建 Web 服务.有一些服务应该返回项目列表.服务返回如下内容:

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>

返回数组的结构为:

'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 定义.

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.

这篇关于如何使用项目列表为soap响应定义WSDL复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:40