我使用 JBoss utils(与 JAX-WS 兼容)生成了一个 Web 服务客户端
使用 Eclipse '来自 wsdl 的 Web 服务客户端'。
因此,我提供的唯一内容是 Web 服务 WSDL 的 url。
现在,Web 服务提供商告诉我更改 Web 服务的“客户端端点应用程序访问的 URL”。
它是什么以及如何改变它?
最佳答案
IMO,提供商告诉您更改服务端点(即到达 Web 服务的位置),而不是客户端端点(我不明白这可能是什么)。要更改服务端点,您基本上有两个选择。
使用 Binding Provider 设置端点 URL
第一个选项是更改 BindingProvider.ENDPOINT_ADDRESS_PROPERTY
BindingProvider
的属性值(每个代理都实现 javax.xml.ws.BindingProvider
接口(interface)):
...
EchoService service = new EchoService();
Echo port = service.getEchoPort();
/* Set NEW Endpoint Location */
String endpointURL = "http://NEW_ENDPOINT_URL";
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
System.out.println("Server said: " + echo.echo(args[0]));
...
缺点是这仅在原始 WSDL 仍可访问时才有效。不建议。
使用 WSDL 获取端点 URL
第二个选项是从 WSDL 获取端点 URL。
...
URL newEndpoint = new URL("NEW_ENDPOINT_URL");
QName qname = new QName("http://ws.mycompany.tld","EchoService");
EchoService service = new EchoService(newEndpoint, qname);
Echo port = service.getEchoPort();
System.out.println("Server said: " + echo.echo(args[0]));
...
关于java - 如何更改网络服务 url 端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6407007/