在SUDS库中更改Web服务URL
使用SUDS这个SOAP客户端时,怎么指定网络服务的地址呢?我看到在客户端的构造函数里已经明确写了WSDL的路径,但如果我想要更改网络服务的地址该怎么办呢?
3 个回答
1
我觉得你需要为每个不同的网址创建一个新的客户端对象。
4
你可以通过两种方法让客户端指向不同的接口:
1) 使用 client.set_options(location='http://path/to/your/wsdl') -或者- 2) 使用客户端的 clone() 方法。然后再用 set_options()。这其实和第一种方法是一样的,不过你会得到两个客户端可以使用,而不是一个。
第二种方法是创建一个轻量级的客户端克隆的干净方式——它们会共享解析后的 WSDL(Web 服务描述语言),只是选项不同,这些选项是通过 set_options() 设置的。
我使用这两种方法,它们都很好用。
-Matt
4
Suds支持有多个服务或多个端口的WSDL(或者两者都有)。不过,由于我对你正在处理的内容没有详细了解,我只能猜测这可能是你想要的。如果你能提供更多细节,比如你的Client
实例是什么样的,这个问题会更容易回答。
在你成功创建了一个Client
之后,可以用print
命令来查看可用的服务、方法、端口和类型。
下面的例子直接来自suds的文档。
来自suds网站的例子:
from suds.client import Client
url = 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'
client = Client(url)
print client
输出结果是:
Suds - version: 0.3.7 build: (beta) R550-20090820
Service (BLZService) tns="http://thomas-bayer.com/blz/"
Prefixes (1)
ns0 = "http://thomas-bayer.com/blz/"
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType
Service (OtherBLZService) tns="http://thomas-bayer.com/blz/"
Prefixes (1)
ns0 = "http://thomas-bayer.com/blz/"
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType
每个服务可以通过多种方式访问,但这里是每个服务中通过方法区分的不同端口:
## service: BLZService, port: soap12, method: getBank
client.service['BLZService']['soap12'].getBank()
## service: OtherBLZService, port: soap, method: getBank
client.service['OtherBLZService']['soap'].getBank()
这就是你正在处理的内容吗?如果是的话,可以去看看他们的文档,我觉得你会觉得很有用。如果不是,请尽量在你的问题中添加更多细节,这样我们才能更好地帮助你!