Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change WebService endpoint address at run time

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!

like image 430
Chan Pye Avatar asked Jan 12 '10 04:01

Chan Pye


2 Answers

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...;
like image 128
Chandra Patni Avatar answered Oct 23 '22 05:10

Chandra Patni


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);
like image 40
peterh Avatar answered Oct 23 '22 03:10

peterh