I used Netbeans to generate Web Sevice client code from WSDL url. But I can't change endpoint address at run time using co开发者_C百科de.
Please help me to solve that problem!
You can do it two ways:
1) Cast port
to BindingProvider
and specify BindingProvider.ENDPOINT_ADDRESS_PROPERTY
property
MyService service = new MyService();
MyPort port = service....
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://New.Endpoint/service");
2) You can call the generated service constructor which takes WSDL URL as parameter.
QName qname = new QName("http://serviceuri/", "service");
String wsdl = "http://New.Endpoint/service?wsdl";
MyServiec service = new MyServiec(new URL(wsdl), qname);
MyPort port = check...;
You can do it all from you service's constructor. JAX-WS will have generated various forms of the constructor for you. This is basically same as what is mentioned as solution #2 in Chandra's answer above.
However I do not think you want code the namespace and the service name once again as is done in that answer. Simply do:
URL wsdl = new URL("http://New.Endpoint/service?wsdl"); MyService wsService = new MyService(wsdlURL);
精彩评论