Wednesday, July 11, 2012

A Simple JAX Web Service

JAX-WS Server Implementation.

Setp 1.
Create a dynamic web project
Step 2.
Create a java file with name SayHello and write following code. To expose as web service annotate the class SayHello with @WebService

 
Step 3.
Create a build.xml, It is an ant file and write below ant script to generate services source code.
However your java compiler must point to JDK-6 where you should have wsgen executable file, so that ant can call this file to generate services file.

 On running this script you will find two generate file under package (source package followed by jaxws) as shown in below image.  In above ant script –cp <<path>> is used to copy generated class file to specified directory. –keep will tell to ant that generated source code should not destroy and –s <<path>> specify the source path to place source file and –d <<path>> is used to define the directory where build file of source code will be available.

 
Step  4.
To expose web-service we need to change in web.xml 

 
Step 5.
Now create a file named sun-jaxws.xml inside WEB-INF directory and provide below entries

Step 6.
Create war of this project and deploy in a server (Tomcat) and test wsdl using below address

                                    
 

Process to create a client for jax-ws

Step 1.
Create a dynamic web project
Step 2. 
Create a build.xml, it is an ant file and write below ant script to generate services source code.
However your java compiler must point to JDK-6 where you should have wsimp executable file, so that ant can call this file to generate services file. 


Step 3.
In marked line you have to place correct wsdl invocation url as stated in Server Side step 6.
On execution above ant-script you well get below structure



Step 4.
To test client create a class as below

That's all.