suds和选择标签

4 投票
3 回答
2089 浏览
提问于 2025-04-16 17:26

如何生成带有“选择”参数的方法请求?

这是一个WSDL的一部分,地址是 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>

当我执行

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

时,我看到

GetMethod()

没有任何参数。

我该如何用byA或byB来调用GetMethod?

3 个回答

0

要知道具体情况,得看看完整的wsdl文件,你给的链接是指向你本地电脑的。

Suds客户端类使用了一个叫做Service Class的东西,来和wsdl进行互动。你有没有试过这样做呢?

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

或者

client.service.GetMethod("byB")

1

我把它修好了,代码如下:

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])
5

这是suds中的一个已知错误。你可以在这里查看详细信息:https://fedorahosted.org/suds/ticket/342

撰写回答