/ cxf

SOAP Web Service Client using Apache CXF

Howdy Folks. Let’s quickly have a look at creating a SOAP web service client using Apache CXF. While there are a number of other libraries to write the SOAP client, I tend to prefer CXF because of the level of maturity and support.

Let’s look at an example of a public Global Weather Service http://www.webservicex.com/globalweather.asmx

Exploring the Service WSDL

The WSDL (Web service description language) file/URL hosts the metadata of the web service and provides you a contract to communicate and get the results of the web service. The WSDL of the GlobalWeaterService WS can be found at http://www.webservicex.com/globalweather.asmx?WSDL

Generating the generated SOAP Data Models

Apache CXF provides convenient binaries to automatically generate SOAP client and data models to execute the remote web service API’s. Here’s an example of generating the clients and the data models.

For the purpose of this post, we are using CXF v3.1.12 (http://cxf.apache.org/download.html)

Underneath the generated SOAP Clients and Data Models

The generated files by the above CXF utilities generate a set of data models for the request and response objects. They are the JAXB annotated Java Objects that will be used by the CXF underneath to convert to the XML payload your web service expects. Here’s how the above command generates few data models.

## Underneath the generated SOAP Client.

The generated SOAP client is a convenient CXF client that can be used directly to access the web service. The generated client is compliant with JAX-WS (JSR 224), the JAVA community standard to develop and define SOAP web service clients.

Putting it all together, Executing the SOAP Web Service Client

Since, most of the work has already been done by the CXF, now its a piece of cake to execute the remote web service. We will use the generated client method passing in the data models with the valid input data. Based on the JAX-WS spec, it also provides convenient endpoints for executing the method directly without building models explicitly.

Love Hasija

Love Hasija

Full Stack Research Engineer, Software Architect | Helped build next generation software systems | Distributed Systems Fanatic | Open Source Hacker.

Read More
SOAP Web Service Client using Apache CXF
Share this