Metro 与 jax-ws 覆盖端点地址
我正在使用 Metro 和 jax-ws 创建一个 Web 服务客户端,并且我想覆盖端点地址。
使用 2.11.1 中的以下示例。 BindingProvider.ENDPOINT_ADDRESS_PROPERTY 我可以这样做: 但是
//Create service and proxy from the generated Service class.
HelloService service = new HelloService();
HelloPort proxy = service.getHelloPort();
((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://new/endpointaddress");
proxy.sayHello("Hello World!");
我不知道不明白为什么我不能使用service.getHelloPort().sayHello("Hello World!") 而不是 proxy.sayHello("Hello World!") 如示例所示。如果这样做,Web 服务客户端将使用其默认端点地址,而不是我想要使用的地址。
看起来每次我调用 getHelloPort() 时都会得到一个 HelloPort 的新实例
有人能解释一下吗?
I'm creating a webservice client using Metro with jax-ws and I want to override the endpoint address.
Using the following example from 2.11.1. BindingProvider.ENDPOINT_ADDRESS_PROPERTY I can do that:
http://metro.java.net/guide/How_to_invoke_and_endpoint_by_overriding_endpoint_address_in_the_WSDL.html
//Create service and proxy from the generated Service class.
HelloService service = new HelloService();
HelloPort proxy = service.getHelloPort();
((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://new/endpointaddress");
proxy.sayHello("Hello World!");
But I don't understand why I can't use the service.getHelloPort().sayHello("Hello World!") instead of proxy.sayHello("Hello World!") as the example shows. If I do, the webservice client is using its default endpoint address instead of the one I want to use.
It looks like I'm getting a new instance of HelloPort every time I call getHelloPort()
Can anyone explain this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们之间几乎没有(读:没有)区别:
并且
service.getHelloPort() 调用将始终返回一个新的代理/端口实例。因此,每当您修改给定端口对象的请求上下文时,该修改都是特定端口实例的本地修改。
一般来说,只要您不修改请求/响应上下文,您返回的端口实例就可以重用并且线程安全。对于您发布的代码示例,它正在修改请求上下文以设置端点地址,因此建议每次需要时获取一个新的端口对象,或者至少为每个需要的线程获取一个新对象一。 (threadlocal 是你的朋友)
there is little (read: no) difference between these:
and
the service.getHelloPort() call will always return a new proxy/port instance. so any time you modify the request context for a given port object that modification is local to the specific port instance.
generally speaking the port instance you get back is re-usable and thread safe as long as you dont modify the request/response contexts. for the code sample you posted, it is modifying the request context to set the endpoint address, so it is advisable to get a new port object either every time you need one, or at the very least get a new object for each thread that needs one. (threadlocal is your friend for this)