2016-09-21 18 views
5

使用複雜類型ZEEP我有一個包含像這樣一個複雜類型的wsdl:如何從WSDL在Python

<xsd:complexType name="string_array"> 
    <xsd:complexContent> 
    <xsd:restriction base="SOAP-ENC:Array"> 
     <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]"/> 
    </xsd:restriction> 
    </xsd:complexContent> 
</xsd:complexType> 

我已決定使用zeep的SOAP客戶端,並希望使用鍵入作爲WSDL中引用的其他方法之一的參數。我似乎無法弄清楚如何使用這種類型。當我通過documentation如何使用WSDL中引用的某些數據結構看,它說,使用client.get_type()方法,所以我做了以下內容:

wsdl = "https://wsdl.location.com/?wsdl" 
client = Client(wsdl=wsdl) 
string_array = client.get_type('tns:string_array') 
string_array('some value') 
client.service.method(string_array) 

這給出一個錯誤TypeError: argument of type 'string_array' is not iterable。我也試過的許多變化以及試圖用像這樣一本字典:

client.service.method(param_name=['some value']) 

這給錯誤

ValueError: Error while create XML for complexType '{https://wsdl.location.com/?wsdl}string_array': Expected instance of type <class 'zeep.objects.string_array'>, received <class 'str'> instead.` 

如果有人知道如何從與ZEEP使用WSDL上述類型, 我會很感激。謝謝。

+0

您是否設法解決了您的問題?我目前面臨類似的問題 – JohnnyQ

+1

對不起,我沒有。由於我的產品沒有使用SOAP,所以不值得花時間去解決。祝你好運,但。 – user197674

回答

7

client.get_type()方法返回一個'類型構造函數',您可以稍後使用它來構造該值。您需要將構造的值分配給單獨的變量,並在方法調用中使用該變量:

wsdl = "https://wsdl.location.com/?wsdl" 
client = Client(wsdl=wsdl) 
string_array_type = client.get_type('tns:string_array') 
string_array = string_array_type(['some value']) 
client.service.method(string_array)