Create a Web Service Client with JAX-WS

This example shows how to create a web service client using JAX-WS reference implementation and its tool ‘wsimport’.
JAX-WS RI can be downloaded from Sun (

To create the web service client we need an existing web service, so we will use the one created in the example ‘Create a simple Web Service’:

Click here to go to the ‘Create a simple Web Service’ example

So we assume the web service is deployed on our local computer and it listens to port 8080.
Go to the bin directory in the jax-ws ri installation directory and run the command wsimport.bat (if Windows, else and pass the url to the wsdl-file as a parameter.

There are a number of options you can pass to the wsimport utility so you might want to run wsimport -help to find out more.
For example, you might want to use the option -keep to prevent the wsimport utility to delete the .java files after compilation.

Now the utility has read the wsdl-file, created the necessary classes and compiled them for us to use.
We can now create the class that will use them and call the web service.

Note that you need the genereated classes and the jax-ws libraries in the classpath when you compile and run the above class.
That is easiest done by pointing them out in your project properties in the IDE.

The output looks something like this:

Search for more Java info on this site here:
Custom Search

Please type any questions here.