9

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!

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Chan Pye
  • 1,391
  • 7
  • 18
  • 32

2 Answers2

15

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...;
Chandra Patni
  • 17,347
  • 10
  • 55
  • 65
3

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);
peterh
  • 18,404
  • 12
  • 87
  • 115