SOAP请求中的复杂数组

时间:2011-11-28 06:55:21

标签: soap soapui

我正在试图弄清楚如何编写SOAP请求的数组部分,其WSDL的相关部分是这样的:

<xsd:complexType name="ArrayOfProductInfo">
    <xsd:complexContent>
        <xsd:restriction base="soap-enc:Array">
            <xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="tns:ProductInfo[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ProductInfo">
    <xsd:all>
        <xsd:element name="productID" type="xsd:string"/>
        <xsd:element name="quantity" type="xsd:int"/>
        <xsd:element name="price" type="xsd:float"/>
    </xsd:all>
</xsd:complexType>
<xsd:complexType name="clCostRequest">
    <xsd:all>
        <xsd:element name="language" type="xsd:string"/>
        <xsd:element name="items" type="tns:ArrayOfProductInfo"/>
        <xsd:element name="shipmentOriginCountry" type="xsd:string"/>
        <xsd:element name="shipmentDestinationCountry" type="xsd:string"/>
    </xsd:all>
</xsd:complexType>

使用soapUI,我能够看到SOAP请求看起来如下,除了我在“????”中包含的内容标签,soapUI没有显示。 (另请注意,它将此节点显示为自动关闭标记。)

<soapenv:Envelope mlns:xsi="http:...">
   <soapenv:Header/>
   <soapenv:Body>
      <clCost soapenv:encodingStyle="http://schemas.xmlsoap.org/...">
         <request xsi:type="clCostRequest">
            <language xsi:type="xsd:string">en</language>
            <items xsi:type="ArrayOfProductInfo" soapenc:arrayType="ProductInfo[]"/>

                <????>productID</????>
                <????>quantity</????>
                <????>price</????>

                <????>productID</????>
                <????>quantity</????>
                <????>price</????>

            <shipmentOriginCountry xsi:type="xsd:string">US</shipmentOriginCountry>
            <shipmentDestinationCountry xsi:type="xsd:string">DE</shipmentDestinationCountry>
         </request>
      </clCost>
   </soapenv:Body>
</soapenv:Envelope>

我需要传入“ProductInfo”数组,但我不知道它的标签应该是什么样子。我试过这个无济于事:

<items xsi:type="ArrayOfProductInfo" soapenc:arrayType="ProductInfo[]">
    <ProductInfo xsi:type="tns:ProductInfo">
        <productID xsi:type="xsd:string">86595</productID>
        <quantity xsi:type="xsd:int">50</quantity>
        <price xsi:type="xsd:float">1.99</price>
     </ProductInfo>
    <ProductInfo xsi:type="tns:ProductInfo">
        <productID xsi:type="xsd:string">12215</productID>
        <quantity xsi:type="xsd:int">60</quantity>
        <price xsi:type="xsd:float">5.99</price>
     </ProductInfo>
</items>

非常感谢任何类似示例的提示或参考!

2 个答案:

答案 0 :(得分:0)

SoapUI将翻译您给他的WSDL并显示请求及其参数。无论从WSDL生成的SOAPUI应该是正确的。因此,我建议您检查您的WSDL,因为错误就在那里。

答案 1 :(得分:0)

这应该工作

    <soapenv:Envelope mlns:xsi="http:...">
   <soapenv:Header/>
   <soapenv:Body>
      <clCost soapenv:encodingStyle="http://schemas.xmlsoap.org/...">
         <request xsi:type="clCostRequest">
            <language xsi:type="xsd:string">en</language>
            <items xsi:type="ArrayOfProductInfo" soapenc:arrayType="ProductInfo[]">
                <item xsi:type="xsd:ProductInfo">
                        <productID xsi:type="xsd:string">86595</productID>
                        <quantity xsi:type="xsd:int">50</quantity>
                        <price xsi:type="xsd:float">1.99</price>
                </item>
                <item xsi:type="xsd:ProductInfo">
                        <productID xsi:type="xsd:string">12215</productID>
                        <quantity xsi:type="xsd:int">60</quantity>
                        <price xsi:type="xsd:float">5.99</price>
                </item>
            </items>

            <shipmentOriginCountry xsi:type="xsd:string">US</shipmentOriginCountry>
            <shipmentDestinationCountry xsi:type="xsd:string">DE</shipmentDestinationCountry>
         </request>
      </clCost>
   </soapenv:Body>
</soapenv:Envelope>