在运行时更改suds客户端的Web服务URL(保留wsdl)

pat*_*tan 8 python wsdl suds

首先,我的问题与类似

但它有点不同.我们拥有的是一系列具有相同服务的环境.对于某些环境(本地环境),我们可以访问wsdl,从而生成suds客户端.对于外部环境,我们无法访问wsdl.但同样,我希望我可以只更改URL而不重新生成客户端.我试过克隆客户端,但它不起作用.


编辑:添加代码:

    host='http://.../MyService.svc'
    wsdl_file = 'file://..../wsdl/MyService.wsdl'

    client = suds.client.Client(wsdl_file, location=host, cache=None)

    #client = baseclient.clone()

    #client.options.location = otherhost

    client.set_options(port='BasicHttpBinding_IMyService')

    result = client.service.IsHealthy()
Run Code Online (Sandbox Code Playgroud)

这给了我这个例外:

由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理带有Action'http://tempuri.org/IMyService/IsHealthy ' 的消息.这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).

问题是,如果我将客户端直接设置为主机,它可以正常工作:client = suds.client.Client(host)

正如您所看到的,我已尝试克隆客户端,但具有相同的异常.我甚至试过这个:

    baseclient = suds.client.Client(host)

    client = baseclient.clone()

    client.options.location = otherhost
    ....
Run Code Online (Sandbox Code Playgroud)

并得到了同样的例外.

有人可以帮帮我吗?

ant*_*ger 6

client.sd[0].service.setlocation(new_url)
Run Code Online (Sandbox Code Playgroud)

...是“手动”方式,即。每个服务描述

client.set_option(new_url)
Run Code Online (Sandbox Code Playgroud)

...也应该有效,根据作者

options 是一个包装/受保护的属性——直接编辑很可能会被忽略。


jat*_*ism 1

您也许可以通过指定location服务来做到这一点。假设您有一个Client名为 的对象client,您可以通过更新 中的 URL 来修改服务位置client.options.location

此外,您还可以使用 WSDL 文件的本地副本作为通过url使用file://URL 方案(例如file:///path/to/service.wsdl. 所以这可能是您的另一种选择。当然,您还必须指定location以便覆盖 WSDL 中的默认位置。