I used Netbeans to generate Web Sevice client code from WSDL url. But I can't change endpoint address at run time using code.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With