JAX-WS webservice example

I am going to give an example on how to create a jax-ws webservice. I will show you how to publish the service in two approaches. First approach for publishing the service will be just using the java main method. Second approach will be by deploying the service in Tomcat Server 7 in another tutorial.
So for first approach, creating the java project from Eclipse is sufficient but as we will deploy the service into the Tomcat Server later on so it’s recommended to create the Dynamic Web Project.

Prerequisites

JDK 1.6
Eclipse 3.6
List of jars
jax-ws webservice example

Download the jar files and put the jar files under WEB-INF/lib directory.

Create the endpoint interface

Create the implementation class

Now we need to publish the service in order to access the service from the client.

The URL format should be http://<host>:<port>/<any path name>/<any service name>, i.e. http://localhost:8888/jax-ws-ssl/hello

WSDL location should be http://<host>:<port>/<any path name>/<any service name>?wsdl, i.e., http://localhost:8888/jax-ws-ssl/hello?wsdl

Now we need to test the service, so we create client class for that.

WSDL file

Now you can use this WSDL file to consume the service from another system. Just generate stub or client java code from the WSDL file and invoke the service. We will see later how to consume webservice.

Thanks for your reading. Please leave a comment if you have any query.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.