了解 WSDL 中的序列和返回数组

Understanding sequences and returning arrays in WSDL

所以我的 Web 服务应该将一列数据 (ID) 和 return 2 列 table 相应数据用于请求的 ID。我知道我应该为此目的使用一个序列,所以我制作了这个模式:

<wsdl:types>
<xsd:schema targetNamespace="urn:myurn" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="GetWSIDListByDPIDList">
    <xsd:complexType>
        <xsd:sequence maxOccurs="unbounded" minOccurs="1">
            <xsd:element name="DPID" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
<xsd:element name="GetWSIDListByDPIDListResponse">
    <xsd:complexType>
        <xsd:sequence maxOccurs="unbounded" minOccurs="0">
            <xsd:element name="DP" type="xsd:string"/>
            <xsd:element name="WSID" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element></xsd:schema>

请求是字符串序列,响应是字符串对序列。似乎是对的。

但是当我开始编写实现代码时(顺便说一句,它是自上而下的方法)我意识到我需要某种第三元素 - 行元素,包含 2 个字符串元素(DP 和 WSID),它是通过 DPIDListRespose 获取 WSIDList。

我正在使用 Axiom 编写实现,所以它看起来像这样:

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("urn:myurn", "urn");
        OMElement response = fac.createOMElement("GetWSIDListByDPIDListResponse",omNs);
        OMElement WSIDListItem = fac.createOMElement("WSIDListItem",omNs);
        OMElement WSID = fac.createOMElement("WSID",omNs);
        WSID.addChild(fac.createOMText("0123123"));
        OMElement DP = fac.createOMElement("DP",omNs);
        DP.addChild(fac.createOMText("0321321"));
        WSIDListItem.addChild(DP);
        WSIDListItem.addChild(WSID);
        response.addChild(WSIDListItem);
        return response;

最后我得到这样的回复:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:GetWSIDListByDPIDListResponse xmlns:urn="urn:fnc.service.livelink.opentext.com">
         <urn:WSIDListItem>
            <urn:DP>0321321</urn:DP>
            <urn:WSID>0123123</urn:WSID>
         </urn:WSIDListItem>
      </urn:GetWSIDListByDPIDListResponse>
   </soapenv:Body>
</soapenv:Envelope>

因此,向响应中添加更多 WSIDListItems 我得到了一些类似 table 的内容。但是看起来不像 WSDL 中描述的那样。我什至不明白响应会如何使用我的 wsdl 描述。

所以问题是 return 2 列数据的正确方法是什么?我的方法是否正确?我应该修复什么、实施或 WSDL 以匹配我的实施?

提前致谢。

好的,所以我自己回答了我的问题。响应,匹配我的 WSDL 看起来像

  <urn:GetWSIDListByDPIDList>
     <DP>1</DP>
     <WSID>2</WSID>
     <DP>3</DP>
     <WSID>4</WSID>
  </urn:GetWSIDListByDPIDList>

这有点误导眼睛。所以我决定更好的决定是改变 wsdl 响应模式和 return DPID 作为属性和值,像这样:

<WSID DPID="Some ID">1</WSID>

同事建议的另一种方法:

<DPID ID = "Some dpID">
  <WSID>1</WSID>
</DPID>