有没有办法向Python Suds客户端提供外部WSDL文件

时间:2013-04-24 17:09:12

标签: python soap wsdl suds

我正在使用SOAP服务,其中项目提供外部WSDL文件。我正在使用Python + Suds连接到该服务。我遇到了问题,因为(https)服务URL看起来像:

/ sipxconfig /服务/ UserService?WSDL

但该URL的WSDL不会 匹配项目提供的外部WSDL文件。返回的 返回的SOAP文档与外部WSDL文件匹配。所以我的泡沫客户端引发了一个错误。

到目前为止,我已经设法通过编写suds插件来“纠正”返回的SOAP XML,以便它与动态创建的WSDL(在URL处)相匹配。但是,我希望有一种方法可以为子客户端提供外部WSDL文件,然后将其切换为使用服务的URL。

我试过这样的事情:

wsdl_file = os.path.abspath(args.wsdl_file)
client = Client("file://%s" % wsdl_file, transport=t, username=sip_user, password=sip_pwd, doctor=doctor)
client.set_options(location=url)

#Get the results.
user_search = client.factory.create("UserSearch")
user_search.byUserName = args.find_user
user_search.byFuzzyUserNameOrAlias = args.fuzzy
user_search.byGroup = args.group

result = client.service.findUser(user_search)
#^^^
#Error here!

但它最终导致MethodNotFound例外。 我在另一个终端运行netstat,我可以看到客户端没有与外部服务建立网络连接。

还有其他人设法从文件中提供Suds WSDL吗?

谢谢, 卡尔

1 个答案:

答案 0 :(得分:2)

所以我确定我在正确的轨道上,但我的SOAP服务有多个端口。我需要做以下事情:

wsdl_file = os.path.abspath(args.wsdl_file)
client = Client("file://%s" % wsdl_file, transport=t, username=sip_user, password=sip_pwd, doctor=doctor)
client.set_options(location=url)

#Get the results.
user_search = client.factory.create("UserSearch")
user_search.byUserName = args.find_user
user_search.byFuzzyUserNameOrAlias = args.fuzzy
user_search.byGroup = args.group

result = client.service['UserService'].findUser(user_search)
#                      ^^^^^^^^^^^^^^^
# This was the missing bit that threw me off!

谢谢, 卡尔