SOAP 请求中的复杂数组

问题描述 投票:0回答:2

我正在尝试弄清楚如何编写 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>

对类似示例的任何提示或参考将不胜感激!

soap soapui
2个回答
0
投票

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


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>
© www.soinside.com 2019 - 2024. All rights reserved.