Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a complex type from a WSDL with zeep in Python

I have a WSDL that contains a complex type like so:

<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>

I have decided to use zeep for the soap client and want to use that type as a parameter to one of the other methods referenced in the WSDL. I can't seem to figure out how to use this type though. When I looked through the documentation on how to use certain data structures referenced in the WSDL, it says to use the client.get_type() method, so I did the following:

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)

This give an error TypeError: argument of type 'string_array' is not iterable. I also tried many variations of that as well as trying to use a dictionary like so:

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

Which gives the error

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.`

If anyone knows how to use the above type from the WSDL with zeep, I would be grateful. Thanks.

like image 418
user197674 Avatar asked Sep 21 '16 02:09

user197674


1 Answers

The client.get_type() method returns a 'type constructor' that you can later use to construct the value. You need to assign the constructed value to a separate variable and use that variable in the method invocation:

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)
like image 196
Kcats Avatar answered Oct 17 '22 19:10

Kcats