javaweb-servicessoapwsdlaxiom

Understanding sequences and returning arrays in WSDL


So my web service is supposed to take one column of data (IDs) and return 2-column table of corresponding data to requested ID's. I understood that I should use a sequence for that purpose so I've made this schema:

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

Request is a sequence of strings and response is a sequence of pair of strings. Seems right.

But when I started to code an implementation (by the way it's top down approach) I realized that I need some kind of third element - row element, containing 2 elements of strings (DP and WSID) which is child of GetWSIDListByDPIDListRespose.

I'm writing implementation using Axiom so It looks something like that:

        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;

And in the end I get response like that:

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

So adding more WSIDListItems to response I get some something like a table. BUT is does not look like what is described in WSDL. I don't even understand how would response would like using my wsdl description.

So the question is what is the correct way to return 2 column data? Is my approach any correct? What should I fix, implementation or WSDL to match my implementation?

Thanks in advance.


Solution

  • Ok, so I kinda answered my question myself. Response, matching my WSDL would look like

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

    Which is sorta missleading to eye. So I've decided that better decision would to alter wsdl response schema and return DPID as an attribute and in value, something like this:

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

    Another approach is suggested by colleague:

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