2016-07-23 106 views
1

ZEEP文檔例如:如何在python soap模塊zeep中處理complexType參數?

from zeep import Client 

client = Client('http://my-enterprise-endpoint.com') 
client.service.submit_order(user_id=1, order={ 
    'number': '1234', 
    'price': 99, 
}) 

我的使用情況:

我想打電話,需要一個參數 'findCriteria'

示例web服務:

findcriteria = { 
     'Criteria' : [{ 
         'ColumnName' : 'Closed', 
         'Value' : 0 
       }, 
       { 
         'ColumnName' : 'AssignToQueueID', 
         'Value' : queueid 
       }, 
       { 
         'ColumnName' : 'SupportCallType', 
         'Value' : 'I' 
       } 
       ] 
     } 

調用服務:

print clien t.service.GetCount(findCriteria = findcriteria)

這是所創建的XML:

<soap-env:Body> 
    <ns1:GetCount> 
     <ns1:findCriteria/> 
    </ns1:GetCount> 
    </soap-env:Body> 
</soap-env:Envelope> 

問題:

雖然服務返回的計數,所述標準是沒有申請。

當我爲服務提供原始XML有效負載時,結果是正常的。

問題出在<ns1:findCriteria/>部分。

對於每一列應該創建一個Criteria元素。在WSDL的grep getCount將的

結果:

<s:element name="GetCount"> 
     <s:element name="GetCountResponse"> 
      <s:element minOccurs="1" maxOccurs="1" name="GetCountResult" type="s:int" /> 
    <wsdl:message name="GetCountSoapIn"> 
    <wsdl:part name="parameters" element="tns:GetCount" /> 
    <wsdl:message name="GetCountSoapOut"> 
    <wsdl:part name="parameters" element="tns:GetCountResponse" /> 
    <wsdl:operation name="GetCount"> 
     <wsdl:input message="tns:GetCountSoapIn" /> 
     <wsdl:output message="tns:GetCountSoapOut" /> 
    <wsdl:operation name="GetCount"> 
     <soap:operation soapAction="http://<server>/webservices/SupportCall/GetCount" style="document" /> 
    <wsdl:operation name="GetCount"> 
     <soap12:operation soapAction="http://<server>/webservices/SupportCall/GetCount" style="document" /> 

回答

0

檢查用下面的命令您的WSDL: python -mzeep <wsdl>

你會發現在輸出服務的細節:ns1:GetCount(FindCriteria:findCriteria)

示例代碼基於在上述檢查輸出上:

find_criteria_type = client.get_type('ns1:findCriteria') 
find_criteria = find_criteria_type() 
client.service.GetCount(FindCriteria=find_criteria) 

如果XML是這樣的:在創建OBJ,當你需要通過PARAMS

<soap-env:Body> 
    <ns1:GetCount> 
    <ns1:findCriteria> 
     <ns1:param1>val1</ns1:param1> 
     <ns1:param2>val2</ns1:param1> 
    </ns1:findCriteria> 
    </ns1:GetCount> 
</soap-env:Body> 

find_criteria = find_criteria_type(param1=val1, param2=val2) 
+0

跟着你的建議,但還是沒有結果。問題出現在('ns1:findCriteria。這不是有效的類型。謝謝你的努力。 – Peter

+0

可以共享命令輸出'python -mzeep | grep GetCount'? –

+0

這個命令不能幫助我,因爲我的wsdl是身份驗證。我放置了wsdl local,但是它試圖包含身份驗證背後的其他模式。 – Peter

1

我有一個類似的問題,我設法解決它,而是幫助你需要一個樣本正確的XML(應該是這樣的樣子)還是至少使用SoapUI生成的默認請求。

與此同時,下面的代碼可能會幫助你: 在這裏,複雜的參數是憑據,它由2個登錄項,登錄和域組成。

<soap-env:Envelope xmlns:ns1="http://xml.kamsoft.pl/ws/kaas/login_types" 
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap-env:Body> 
    <ns1:login> 
     <ns1:credentials> 
     <ns1:item> 
      <ns1:name>login</ns1:name> 
      <ns1:value> 
      <ns1:stringValue>login_here</ns1:stringValue> 
      </ns1:value> 
     </ns1:item> 
     <ns1:item> 
      <ns1:name>domain</ns1:name> 
      <ns1:value> 
      <ns1:stringValue>domain_here</ns1:stringValue> 
      </ns1:value> 
     </ns1:item> 
     </ns1:credentials> 
     <ns1:password>password_here</ns1:password> 
    </ns1:login> 
    </soap-env:Body> 
</soap-env:Envelope> 

這裏是產生這個XML代碼:

domain = "domain_here" 
login = "login_here" 
password = "password_here" 
credentials = {"item": [{"name": "login", 'value': {"stringValue": login}}, 
         {"name": "domain", 'value': {"stringValue": domain}}]} 
client.service.login(credentials=credentials, password=password)