overriding or setting web service endpoint at runtime for code generated with wsimport

Your client can set the end-point in the service “port” at runtime via the BindingProvider interface.

Consider the JAX-WS client in this JAX-WS tutorial. Another way to write this code would be:

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);

Caveat: I haven’t downloaded the tutorial code and tested this code against it.

Leave a Comment