Searching...
Wednesday, 7 August 2013

JAX-WS Web services using Apache CXF

10:02
In this example we are using Apache CXF for JAX-WS implementation , see more about Apache CXF

Software Used

  1. Eclipse Kepler Release
  2. Tomcat 6
  3. Java 1.6
  4. CXF 2.7.6

Environment Setup

1. Download apache CXF from http://www.apache.org/dyn/closer.cgi?path=/cxf/2.7.6/apache-cxf-2.7.6.zip
2. Extract CXF zip file
3. Setup CXF run time in eclipse
Go to Eclipse Window->Preference->Web services and select CXF run time
image 

Create Web Service

1. Create a Dynamic web project in eclipse and choose Tomcat 6 as Target run time
image 
2. Create a java class to implement Web service method
 
package com.pretech;

public class MyWebService {

    public String giveWelcome(String name) {
        return "Welcome " + name;
    }

}
 
3. Right click on the dynamic web project and create a new web service
image 
4. Click on next button and we can see the below window
image 
1.Select web service implementation class (MyWebService)
2.Slider should be in Start Service point
3.Service Runtime should be Tomcat 6
4.Web service run time should be Apache CXF
5.Service project should be this project
6.Check Publish the Web service option
5. Click on next and start the server and click on finish .That's all Web service implementation is done now we can see the generated wsdl file.
image 

Test Web Service

1. Go to Eclipse run-> and Launch Web services Explorer
2. Click on WSDL page and enter the WSDL url (Open MyWebService.wsdl file and get the wsdlsoap:address and append ?wsdl) example :http://localhost:8080/JAX-WS-CXF/services/MyWebService?wsdl

image 
image 

3. Click on go button and we can see the web service methods over there in the next screen. Select giveWelcome method and test it.

image 

0 comments: