How to create a CXF webservice client with dynamic endpoint?

Marco picture Marco · Sep 16, 2011 · Viewed 15.5k times · Source

We have a central WSDL file that describes a web service. We use CXF to generate client code, but this code seems to be bound to 1 endpoint. How can i create a CXF client that uses the WSDL, but where I can specify the endpoint? Is there are way in changing the endpoint to a URL that implements the same WSD:?

Answer

Daniel Kulp picture Daniel Kulp · Sep 16, 2011

If the other service implements the same WSDL, when you create the MyClientService object, you can pass the URL to the new service's WSDL right to the constructor and it will us it. Most services would expose its wsdl on ?wsdl so using that may "just work".

Alternatively, you can override the endpoint URL via:

((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_URL, "http://my.service.url.com/...")

where proxy is the MyClientService object.