suds and choice tag

Question:

how to generate request to method with “choice” arguments?

part of wsdl at http://127.0.0.1/service?wsdl:

<xs:complexType name="ByA">
<xs:sequence>
...
</xs:sequence>
</xs:complexType>
<xs:complexType name="ByB">
<xs:sequence>
...
</xs:sequence>
</xs:complexType>

<xs:complexType name="GetMethodRequest">
<xs:choice>
<xs:element name="byA" type="s0:ByA" />
<xs:element name="byB" type="s0:ByB" />
</xs:choice>
</xs:complexType>

when I do

from suds.client import Client
client = Client("http://127.0.0.1/service?wsdl")
print client

I see

GetMethod()

without any arguments.

how I can call GetMethod with byA or with byB?

Asked By: Andrey Koltsov

||

Answers:

It’s hard to know without seeing the whole wsdl, your link is to your local machine.

The Suds Client class uses the Service Class as an instance variable for interacting with wsdl. Have you tried something like this?

from suds.client import Client
client = Client("http://127.0.0.1/service?wsdl")
client.service.GetMethod("byA")

or

client.service.GetMethod("byB")

Answered By: supersighs

It’s a known bug in suds
https://fedorahosted.org/suds/ticket/342

Answered By: Andrey Koltsov

I fixed it so:

class MyPlugin(DocumentPlugin):
    def setChoice(self, context):
        if not context.children:
            return
        for i in context.children:
            if i.name == "choice":
                for j in i.children:
                    i.parent.append(j)
            else:
                self.setChoice(i)

    def parsed(self, context):
        self.setChoice(context.document)


plugin = MyPlugin()
client = Client("http://127.0.0.1/service?wsdl", plugins=[plugin])
Answered By: Kedr
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.