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

发布于 2024-09-01 13:17:57 字数 1268 浏览 8 评论 0原文

首先,我的问题类似于 这个

但它是一个有点不同。 我们拥有的是一系列环境,具有相同的服务集。 对于某些环境(本地环境),我们可以访问 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬花如无物 2024-09-08 13:17:57
client.sd[0].service.setlocation(new_url)

...是“手动”方式,即。 每个服务说明

client.set_option(new_url)

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

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

client.sd[0].service.setlocation(new_url)

...is the "manual" way, ie. per service-description.

client.set_option(new_url)

...should also work, per the author.

options is a wrapped/protected attr -- direct edits may very well be ignored.

德意的啸 2024-09-08 13:17:57

我明白了!
我什至不知道我是怎么想出来的,但经过一些猜测和运气,我最终得到了这个:

    wsdl_file = 'file://...../MyService.wsdl'

    client = suds.client.Client(wsdl_file)
    client.wsdl.url = host #this line did the trick

    client.set_options(port='BasicHttpBinding_IMyService')

    result = client.service.IsHealthy()

而且它有效!
我找不到有关该属性(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:

    wsdl_file = 'file://...../MyService.wsdl'

    client = suds.client.Client(wsdl_file)
    client.wsdl.url = host #this line did the trick

    client.set_options(port='BasicHttpBinding_IMyService')

    result = client.service.IsHealthy()

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.

丶情人眼里出诗心の 2024-09-08 13:17:57

您可以通过指定服务的位置来做到这一点。假设您有一个名为 clientClient 对象,您可以通过更新 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 a Client object called client, you can modify the service location by updating the URL in client.options.location.

Additionally you are able to use a local copy of a WSDL file as the url when constructing the client by using a file:// 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 the location so that the default location from within the WSDL is overridden.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文