开发者

WSDL list of complexType HOWTO- define, return from a service?

开发者 https://www.devze.com 2023-01-07 07:50 出处:网络
How do you define a list of complex type items in WSDL? I have a rather simple WSDL with 2 complex types

How do you define a list of complex type items in WSDL?

I have a rather simple WSDL with 2 complex types

<xsd:complexType name="itemProperty">
    <xsd:all>
        <xsd:element name="name" type="xsd:string" />
                <xsd:element name="value" type="xsd:string" />
                <xsd:element name="type" type="xsd:string" />
    </xsd:all>
</xsd:complexType>

Then i'm trying to make a list of this complexType like this:

<xsd:complexType name="itemPropertyList">
    <xsd:complexContent>
        <xsd:restriction base="SOAP-ENC:Array">
            <xsd:sequence>
                <xsd:element name="item" type="tns:itemProperty"
                    maxOccurs="unbounded" minOccurs="0" />
            </xsd:sequence>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>

I intend to use this list

<message name="getListRequest"></message>
<message name="getListResponse">
    <part name="return" type="tns:itemPropertyList" />
</message>
<operation name="getList">
    <documentation>Returns an array.</documentation>
    <input message="tns:getListRequest" />
    <output message="tns:getListResponse" />
</operation>

Instead of a list of elements of type itemProperty, I get this reply, no matter what variations i've tryed (including replacing the base item with the explicit string elements)

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
    <ns1:getListResponse>
    <return SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
    <item xsi:type="ns2:Map">
    <item>
        <key xsi:type="xsd:string">name</key>
        <value xsi:type="xsd:string">name_4c3b38b0b77ae</value>
    </item>
    <item>
        <key xsi:type="xsd:string">value</key>
        <value xsi:type="xsd:string"开发者_StackOverflow>name_4c3b38b0b77ee</value>
    </item>
    <item>
        <key xsi:type="xsd:string">type</key>
        <value xsi:type="xsd:string">name_4c3b38b0b782b</value>
    </item>
    </item>
    </return>
    </ns1:getListResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Any ideas? What is this ns2:Map thing? It's been haunting me for over a week!


Solved.

I used the AXIS model for delivering lists. This involved extending the namespaces attributes to include some extra encodings. I don't know which did the trick, I just added as many as possible while resolving conflicts with the help of eclipse's WSDL editor.

<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="urn:mynamespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/" 
targetNamespace="urn:mynamespace"
xmlns:ns1="http://org.apache.axis2/xsd" 
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ax21="http://example.org/xsd" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">

Also I added 2 extra attributes to declare qualified-form attributes and elements within the schema

<xsd:schema targetNamespace="urn:mynamespace" attributeFormDefault="qualified" elementFormDefault="qualified">
    ...
</xsd:schema>    

Instead of relying on the ComplexType declaration to make a "nillable" unbounded sequence of a complex type within my schema, I switched to declare an element like this:

<xsd:element name="getListResponse">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="tns:itemProperty" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>    

Then, when defining the message part for the operation I used

<message name="getListResponse">
    <part name="parameters" element="tns:getListResponse" />
</message>    

instead of

<message name="getListResponse">
    <part name="return" type="tns:itemPropertyList" />
</message>    

This resulted in a correct enveloper returned:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:mynamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <ns1:getListResponse>
        <parameters xsi:type="ns1:getListResponse">
            <return xsi:type="ns1:itemProperty">
                <name xsi:type="xsd:string">name4c4417b644a8e</name>
                <value xsi:type="xsd:string">value4c4417b644aaa</value>
                <type xsi:type="xsd:string">type4c4417b644ae8</type>
            </return>
            <return xsi:type="ns1:itemProperty">
                <name xsi:type="xsd:string">name4c4417b644b26</name>
                <value xsi:type="xsd:string">value4c4417b644b64</value>
                <type xsi:type="xsd:string">type4c4417b644ba1</type>
            </return>
            <return xsi:type="ns1:itemProperty">
                <name xsi:type="xsd:string">name4c4417b644bdf</name>
                <value xsi:type="xsd:string">value4c4417b644c1c</value>
                <type xsi:type="xsd:string">type4c4417b644c59</type>
            </return>
        </parameters>
    </ns1:getListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
0

精彩评论

暂无评论...
验证码 换一张
取 消