Friday, January 20, 2012

JAX-WS Awesome Tutorial

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:
01.package juma.mohammad;
02. 
03.import javax.jws.WebMethod;
04.import javax.jws.WebService;
05. 
06.@WebService
07.public interface Greeting {
08.@WebMethod String sayHello(String name);
09.}
3) Create WS-Service Endpoint Implementation class:
01.package juma.mohammad;
02. 
03.import javax.jws.WebService;
04. 
05.@WebService(endpointInterface = "juma.mohammad.Greeting")
06.public class GreetingImpl implements Greeting {
07. 
08.@Override
09.public String sayHello(String name) {
10.return "Hello, Welcom to jax-ws " + name;
11.}
12. 
13.}
4) Create Endpoint Publisher class:
01.package juma;
02. 
03.import javax.xml.ws.Endpoint;
04. 
05.import juma.mohammad.GreetingImpl;
06. 
07.public class WSPublisher {
08.public static void main(String[] args) {
09.Endpoint.publish("http://localhost:8080/WS/Greeting",new GreetingImpl());
10.}
11.}
5) Run the WSPublisher…. Guess what .. your WebService is published..
Wow.. check your service wsdl http://localhost:8080/WS/Greeting?wsdl

http://java.dzone.com/articles/jax-ws-hello-world

No comments:

Post a Comment