Wednesday, December 7, 2011

Building Web Services with Axis2


Web services

A Web service is a method of communication between two electronic devices over a network. Web Services are published, found, and used through the Web. 

What are Web Services?
  • Web services are application components
  • Web services communicate using open protocols
  • Web services are self-contained and self-describing
  • Web services can be discovered using UDDI
  • Web services can be used by other applications
  • XML is the basis for Web services
 Axis2
Axis2 is an apache open source project.  Apache Axis is a Web Services / SOAP / WSDL engine. There are two implementations of the Apache Axis2 Web services engine - Apache Axis2/Java and Apache Axis2/C.
Click http://axis.apache.org/ to read more about Axis2
 
Step 1: Load Axis2
Download Axis2 from apache site and place it in your local.
Open your Eclipse IDE and go to Window-> Preferences-> Web Services-> Axis2 Preferences and
browse axis2 home directory. If axis2 loaded successfully, “Axis2 runtime loaded successfully” will display in the same window.

Go to “Axis2 Preferences” tab in the same window, select “Generate an interface for skeleton”.
Click “Apply” and “Ok”.
















Step 2: Add Runtime Environments

                Go to Window-> Preferences-> Server-> Runtime Environments-> Click Add button and select your server.



Click Next and Browse the server home directory and select Installed JREs. Click Finish.

Step 3: Create Project

                Create “Dynamic Web Project” in your workspace.  Create a folder called wsdl under WebContent folder and place your WSDL file.

Right click on the WSDL file and go to Web Services-> Generate Java bean skeleton.

Web service type: Top down Java bean Web Service
Service definition: <your WSDL absolute path>


Configuration:
Server: <Configured Runtime Environment>
Web Service runtime: Apache Axis2 (if not, click on the link and change it.)
Service Project: <your wsdl name>

Select “Publish the Web Service” checkbox. Click Next




















Change Custom package name, if you want to move axis2 class to new package.




















Axis2 engine will generate Java bean classes under com.test.ws.axis2 package based on the WSDL used.

Go to com.test.ws.axis2, there will be class called Hello_ServiceSkeleton.java. This is the entry point of the web service.

    package com.test.ws.axis2;
    /**
     *  Hello_ServiceSkeleton java skeleton for the axisService
     */
    public class Hello_ServiceSkeleton implements Hello_ServiceSkeletonInterface{
       
        
        /**
         * Auto generated method signature
         *
         * @param sayHello0
         */
       
                 public helloservice.examples.SayHelloResponse sayHello
                  (
                  helloservice.examples.SayHello sayHello0
                  )
            {
                //TODO : fill this with the necessary business logic
                throw new  java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#sayHello");
        }
    
    }
   

 When a SOAP message is posted to Hello_Service web service, axis2 will convert it to SayHello object.






No comments:

Post a Comment