![](/img/trans.png)
[英]Is the java source code generated from “wsimport <wsdl_url>” is actual soap web service code?
[英]overriding or setting web service endpoint at runtime for code generated with wsimport
使用wsimport
生成的代码,是否可以重写服务端点而无需重新生成代码?
我写了一个简单的java webservice,以下是步骤:
wsimport http://localhost:8080/service/helloservice?Wsdl
问题是服务是部署在8080以外的端口上运行的应用服务器上,客户端和服务之间的通信永远不会发生。 我想知道在客户端使用的存根中创建没有服务器和端口硬编码的存根的最佳方法是什么。
您的客户端可以在运行时通过BindingProvider接口在服务“端口”中设置端点 。
在这个JAX-WS教程中考虑JAX-WS客户端。 编写此代码的另一种方法是:
HelloService service = new HelloService();
Hello port = service.getHelloPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://foo:8086/HelloWhatever");
String response = port.sayHello(name);
警告:我没有下载教程代码并针对它测试了这段代码。
我遇到了同样的问题,而且一旦代码转移到生产环节它很糟糕,它总是寻找硬编码的WSDL位置,即Windows C:........等
我已经通过各种帖子和页面找到答案但是所有都失败了然后通过查看由JAX-WS导入生成的服务类找到了自己的方式。
我不得不像这样覆盖我的调用类中的JAX-WS WSDL位置实现。
URL baseUrl;
URL wsdlURL = null;
baseUrl = <your Services>.class.getResource(".");
try {
wsdlURL = new URL(baseUrl, "http://<your path>?wsdl");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
<your Services> yourServices = new <your Services(wsdlURL,new QName("your namespace", "<your service name>"));
System.out.println(Services.getWSDLDocumentLocation());
YourInterface YourInterfacePort = yourServices.getServicePort();
BindingProvider bindingProvider = (BindingProvider)YourInterfacePort;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
YourInterfacePort.methods();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.