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 (http://java.sun.com).

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 wsimport.sh) 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


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">