Over a million developers have joined DZone.

JAX-WS Five Minute Tutorial

DZone's Guide to

JAX-WS Five Minute Tutorial

This tutorial is for people who want to run a JAX-WS example (Endpoint + Client) in just five minutes.

· Integration Zone
Free Resource

Today’s data climate is fast-paced and it’s not slowing down. Here’s why your current integration solution is not enough. Brought to you in partnership with Liaison Technologies.

This tutorial is for people who want to run a JAX-WS example (Endpoint + Client) in just five minutes.

What you need to run this example:

  1. JDK 1.6
  2. Eclipse .
  3. Be Excited ;)

 Note:- You can download the source code for this example from the resources section.

Developing WebService End Point

1) Open Eclipse, and create a java project "WS-Server".

2) Create WS-Service Endpoint Interface:

package juma.mohammad;import javax.jws.WebMethod;import javax.jws.WebService;@WebServicepublic interface Greeting { @WebMethod String sayHello(String name);}

3) Create WS-Service Endpoint Implementation class:

package juma.mohammad;import javax.jws.WebService;@WebService(endpointInterface = "juma.mohammad.Greeting")public class GreetingImpl implements Greeting {@Overridepublic String sayHello(String name) {return "Hello, Welcom to jax-ws " + name;}}

4) Create Endpoint Publisher class:

package juma;import javax.xml.ws.Endpoint;import juma.mohammad.GreetingImpl;public class WSPublisher {public static void main(String[] args) {Endpoint.publish("http://localhost:8080/WS/Greeting",new GreetingImpl());}}

5) Run the WSPublisher…. Guess what .. your WebService is published..
Wow.. check your service wsdl http://localhost:8080/WS/Greeting?wsdl

Developing WebService Client :

1) Open eclipse and create a new java project WS-Client

2) As you know we need to generate the client stubs... but how?

open your command line, and enter the wsimport command:

CD %CLIENT_PROJECT_HOME%\srcwsimport –s . http://localhost:8080/WS/Greeting?wsdl

You will find 6 java classes generated, and compiled under src/juma/mohammad.

You can remove *.class files , no need for them :)

3) Now Lets create Client Class which will be dependent on the stubs:

package juma;import juma.mohammad.Greeting;import juma.mohammad.GreetingImplService;public class Client {public static void main(String[] args){GreetingImplService service = new GreetingImplService();Greeting greeting = service.getGreetingImplPort(); System.out.println("------->>  Call Started");System.out.println(greeting.sayHello("Ali"));System.out.println("------->>  Call Ended");}}

4) Run the Client Class.... the output should looks like:

------->>  Call StartedHello, Welcom to jax-ws Ali------->>  Call Ended

Congratulations.... you managed to develop jax-ws Endpoint , Client..

The next tutorial will be how to deploy your Web Service on Tomcat.

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and iPaaS+ could cost you down the road. Brought to you in partnership with Liaison Technologies.

java ,jax-ws

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}