13

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.

abahgat
  • 13,360
  • 9
  • 35
  • 42
user197674
  • 748
  • 2
  • 7
  • 22
  • Did you manage to solve your problem? I am facing a similar issue at the moment – JohnnyQ Oct 05 '16 at 15:29
  • 1
    Sorry, I did not. Since SOAP is not used as much on my product, it wasn't worth the time to try to solve. Good luck to you though. – user197674 Oct 06 '16 at 20:03

1 Answers1

17

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)
Kcats
  • 884
  • 1
  • 15
  • 26
  • Could I bother you to take a look at this Zeep related question? It has a bounty on it. https://stackoverflow.com/questions/54201921/in-python-how-to-set-soapheaders-for-zeep-using-dictionaries – Liquidgenius Jan 18 '19 at 02:31
  • This doesn't work for me, seems like the "method" method has been removed – dasfacc Sep 23 '22 at 11:29