2009-09-04 45 views
2

我回答一個WSDL請求的服務器(了SoapUI)。肥皂WSDL的ComplexType被張貼錯誤的參數類型

當發送測試請求,我的服務器代碼接收列表的參數,但我想實現的是一個說法,複雜類型,例如:

{ 
ingredient_id => INT 
something  => STRING 
... 
} 

我的類型如下:

<wsdl:types> 
    <xsd:schema targetNamespace="/ingredient"> 
     <xsd:element name="getIngredientInfo" type="tns:IngredientRequest"></xsd:element> 
     <xsd:element name="getIngredientInfoResponse" type="tns:ingredient"></xsd:element> 

     <xsd:complexType name="ingredient"> 
     <xsd:sequence> 
      <xsd:element name="ingredient_id" type="xsd:int" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="ingredient_name" type="xsd:string" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="status_gm" type="xsd:boolean" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="status_vegan" type="xsd:boolean" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="status_vegetarian" type="xsd:boolean" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="author_id" type="xsd:int" block="#all" minOccurs="1" maxOccurs="1"></xsd:element> 
     </xsd:sequence> 
     </xsd:complexType> 

     <xsd:complexType name="IngredientRequest"> 
     <xsd:sequence> 
      <xsd:element name="ingredient_id" type="xsd:int"></xsd:element> 
      <xsd:element name="something" type="xsd:string"></xsd:element> 
     </xsd:sequence> 
     </xsd:complexType> 

    </xsd:schema> 
    </wsdl:types> 

有人可以幫助我理解爲什麼WSDL使SoapUI發送參數作爲列表simp而不是一個複雜的論點?

編輯:這可能是有些問題具有序列標籤,但我不能找到這個問題,只是需要一些光。 在此先感謝!


當然,我就在這裏:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<wsdl:definitions 
    name="ingredient" 
    targetNamespace="/ingredient" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:tns="/ingredient" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <wsdl:types> 
    <xsd:schema targetNamespace="/ingredient"> 
     <xsd:element name="getIngredientInfo" type="tns:IngredientRequest"></xsd:element> 
     <xsd:element name="getIngredientInfoResponse" type="tns:ingredient"></xsd:element> 

     <xsd:complexType name="ingredient"> 
     <xsd:sequence> 
      <xsd:element name="ingredient_id" type="xsd:int" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="ingredient_name" type="xsd:string" minOccurs="1" maxOccurs="1"></xsd:element> 

      <xsd:element name="status_gm" type="xsd:boolean" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="status_vegan" type="xsd:boolean" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="status_vegetarian" type="xsd:boolean" minOccurs="1" maxOccurs="1"></xsd:element> 
      <xsd:element name="author_id" type="xsd:int" block="#all" minOccurs="1" maxOccurs="1"></xsd:element> 
     </xsd:sequence> 
     </xsd:complexType> 


     <xsd:complexType name="IngredientRequest"> 
     <xsd:sequence> 
      <xsd:element name="ingredient_id" type="xsd:int"></xsd:element> 

      <xsd:element name="something" type="xsd:string"></xsd:element> 
     </xsd:sequence> 
     </xsd:complexType> 
    </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="getIngredientInfoRequest"> 
    <wsdl:part element="tns:getIngredientInfo" name="parameters"/> 
    </wsdl:message> 
    <wsdl:message name="getIngredientInfoResponse"> 

    <wsdl:part element="tns:getIngredientInfoResponse" 
     name="parameters" /> 
    </wsdl:message> 
    <wsdl:portType name="ingredient"> 
    <wsdl:operation name="getIngredientInfo"> 
     <wsdl:input message="tns:getIngredientInfoRequest"/> 
     <wsdl:output message="tns:getIngredientInfoResponse"/> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="ingredientSOAP" type="tns:ingredient"> 

    <soap:binding style="document" 
     transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="getIngredientInfo"> 
     <soap:operation 
      soapAction="http://entropy.homelinux.org/kasak/" /> 
     <wsdl:input> 
      <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
      <soap:body use="literal" /> 
     </wsdl:output> 

    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="ingredient"> 
    <wsdl:port binding="tns:ingredientSOAP" name="ingredientSOAP"> 
     <soap:address location="http://entropy.homelinux.org/kasak/"/> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

仍然沒有提示就可以了:(

回答

10

你需要寫在「文檔/文字包裝」樣式中的WSDL。這些WSDL風格有點令人困惑,但here是一個很好的比較。

在本質上,你需要換你complexTypeelement

<element name="IngredientInfo"> 
    <complexType> 
    <sequence> 
      <element name="ingredient_id" type="xsd:int"></xsd:element> 
      <element name="something" type="xsd:string"></xsd:element> 
    </sequence> 
    </complexType> 
</element> 

,並指定這個element要發送的消息

<message name="getIngredientInfoRequest"> 
    <part name="parameters" element="IngredientInfo"/> 
</message> 

因此所產生的SOAP消息中包含此IngredientInfo-element爲SOAP主體的獨生子女:

<soap:envelope> 
    <soap:body> 
     <IngredientInfo> 
      <ingredient_id>42</ingredient_id> 
      <something>"What is..."</something> 
     </IngredientInfo> 
    </soap:body> 
</soap:envelope> 
+0

中遵循完整評論爲什麼SOAP請求中的WSDL和'ingredient'中的'ingredient_id'? – 2016-02-24 09:11:13

1

我不認爲WSDL類型(IngredientRequest)是問題,你可以顯示完整的WSDL,尤其是它的操作要測試如果這是接受IngredientRequest類型的數組,那麼這就是答案,爲什麼SOAP UI正在發送的參數列表。

+0

當然可以!將在下一個回答 – 2009-09-14 03:12:18

0

使用WSDL生成這裏用我的SOAP UI的示例請求後確定是我所看到的是看到了它的創建單一getIngredientInfo請求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ing="/ingredient"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ing:getIngredientInfo> 
     <ingredient_id>?</ingredient_id> 
     <something>?</something> 
     </ing:getIngredientInfo> 
    </soapenv:Body> 
</soapenv:Envelope> 

所以沒有對象數組。請確認,如果需要,請嘗試使用最新版本的SOAP UI!

0

我的理解是,你現在有類似如下(我做在Java Web服務調用,所以我會在例如它):

SOAPCaller.getIngredientInformation(3, "something"); 

但是,你真正如下所示:

IngredientRequest ingredientRequest = new IngredientRequest(3, "something"); 
SOAPCaller.getIngredientInformation(ingredientRequest); 

嘗試類似Wierob建議的操作會導致第一種情況是由我產生的。不幸的是,我發現實現第二種方法的唯一方法是做額外的封裝,這是一團糟(生成額外的類)。然而,它允許發送單個對象並返回單個對象,而不是許多對象。這裏有一個例子:

<!-- assume the including of your complex types from above --> 
<xsd:element name="getIngredientInfo" > 
    <xsd:complexType> 
    <xsd:sequence> 
     <xsd:element name="ingredient" type="tns:IngredientRequest" /> 
    </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 

<xsd:element name="getIngredientInfoResponse" > 
    <xsd:complexType> 
    <xsd:sequence> 
     <xsd:element name="ingredientResponse" type="tns:ingredient" /> 
    </xsd:sequence> 
    </xsd:complexType> 
</xsd:element>