This question already has answers here:
How to change webservice url endpoint?
(4个答案)
5年前关闭。
如何动态更改我的JAXWS客户端使用的地址?
该客户端由wsimport生成。
(4个答案)
5年前关闭。
如何动态更改我的JAXWS客户端使用的地址?
该客户端由wsimport生成。
最佳答案
您可以使用BindingProvider接口(interface)来实现。
JAX-WS custom endpoint
/**
* The following snippets shows how to set a custom endpoint for a JAX-WS generated WebClient on runtime
*/
// Get the service and the port
SampleService service = new SampleService();
Sample port = service.getESamplePort();
// Use the BindingProvider's context to set the endpoint
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.aviramsegal.com/ws/sample");
/* Optional credentials */
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
port.callSampleMethod();
07-23 12:08