在运行时更改 suds 客户端的 Web 服务 URL(保留 wsdl)
首先,我的问题类似于 这个
但它是一个有点不同。 我们拥有的是一系列环境,具有相同的服务集。 对于某些环境(本地环境),我们可以访问 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()
这给了我这个例外:
带有 Action 'http://tempuri.org/IMyService/ 的消息由于 EndpointDispatcher 上的 ContractFilter 不匹配,IsHealthy' 无法在接收方进行处理。这可能是因为合同不匹配(发送者和接收者之间的操作不匹配)或发送者和接收者之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
问题是,如果我将客户端直接设置为主机,它就可以正常工作: client = suds.client.Client(host)
如您所见,我尝试克隆客户端,但有同样的例外。我什至尝试过这个:
baseclient = suds.client.Client(host)
client = baseclient.clone()
client.options.location = otherhost
....
并得到了同样的例外。
有人可以帮助我吗?
First of all, my question is similar to this one
But it's a little bit different.
What we have is a series of environments, with the same set of services.
For some environments (the local ones) we can get access to the wsdl, and thus generating the suds client.
For external environment, we cannot access the wsdl. But being the same, I was hoping I can change just the URL without regenerating the client.
I've tried cloning the client, but it doesn't work.
Edit: adding code:
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()
That gives me this exception:
The message with Action 'http://tempuri.org/IMyService/IsHealthy' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
The thing is, if I set the client directly to the host, it works fine:
client = suds.client.Client(host)
As you can see, I've tried cloning the client, but with the same exception. I even tried this:
baseclient = suds.client.Client(host)
client = baseclient.clone()
client.options.location = otherhost
....
And got the same exception.
Anyone can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
...是“手动”方式,即。 每个服务说明。
...也应该有效,根据作者。
options
是一个包装/保护的attr——直接编辑很可能会被忽略。...is the "manual" way, ie. per service-description.
...should also work, per the author.
options
is a wrapped/protected attr -- direct edits may very well be ignored.我明白了!
我什至不知道我是怎么想出来的,但经过一些猜测和运气,我最终得到了这个:
而且它有效!
我找不到有关该属性(client.wsdl.url)的任何文档,但它有效,因此我将其发布以防有人遇到同样的问题。
I've got it!.
I don't even know how I've figured it out, but with a little of guessing and a much of luck I ended up with this:
And it works!
I can't find any documentation about that property (client.wsdl.url), but it works, so I post it in case someone have the same problem.
您可以通过指定服务的
位置
来做到这一点。假设您有一个名为client
的Client
对象,您可以通过更新client.options.location
中的 URL 来修改服务位置。此外,在使用
file://
方案作为 URL 构建客户端时,您可以使用 WSDL 文件的本地副本作为url
,例如文件:///path/to/service.wsdl
。所以这可能是您的另一种选择。当然,您还必须指定位置
,以便覆盖 WSDL 中的默认位置。You might be able to do that by specifying the
location
of the service. Assuming you have aClient
object calledclient
, you can modify the service location by updating the URL inclient.options.location
.Additionally you are able to use a local copy of a WSDL file as the
url
when constructing the client by using afile://
scheme for the URL, e.g.file:///path/to/service.wsdl
. So this could be another option for you. Of course you would also have to specify thelocation
so that the default location from within the WSDL is overridden.