Changing Endpoint Address in JAX-WS Web Service Clients

Saturday, March 06, 2010

Using JAX-WS in Java to build a Web Service client starting from WSDL causes wsimport tool to generate all the required code artifacts useful to invoke the Web Service operations.
The generated code refers by default to the WSDL URL from which the client artifacts were generated; this is a comfortable solution in many cases but:
how to change the endpoint address if we want the client to invoke the same service deployed at another URL?

A solution is to use the class.

So, before invoking an operation we can use this class as follows in bold (the code snippet refers to a simple Web service client):

[...] service = new; port = service.getUtilityWebServicePort();


//change endpoint address, where [NEW-SERVICE-ENDPOINT-URL] is the new URL.         ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,


//invoke a Web service operation
java.lang.String result = port.createAccount(account, address);

You Might Also Like

0 commenti