Creating web service from java class using Axis

Axis provides excellent platform for web service creation and deployment. Let's say you have a plain java class that you would like to expose as a web service. You can achieve this in few minutes. I assume here axis.war is already deployed on to your app server.

1. Create your java class with the method that you want to expose. (Its not web service aware.. so you don’t need to implement any interface etc.)

2. Now, register your web service with Axis. Simply add entry following entry to axis.war\WEB-INF\server-config.wsdd.

 <service name="WebServiceDemo" provider="java:RPC">

                       <parameter name="className" value="test.wbservice.Demo"/>

  <parameter name="allowedMethods" value="*"/>

                                           <parameter name="wsdlTargetNamespace" value="http://test.wbservice"/>

                                                                                </service>

 

 Class Name is fully qualified name of the class created in step 1. Now copy demo.class file to axis.war\WEB-INF\lib. If you prefer, You can create jar file containing this class and copy that to lib directory.


3. Restart your app server

4. Now you have deployed web successfully. You can check that using http://appsever_url/axis/services/webserviceDemo

    You can generate WSDL file containing all information of your web service using  http://appsever_url/axis/services/webserviceDemo?wsdl

5. Now You can generate client side stubs and classes required using WSDL2Java tool provided by axis.

   You have to execute this class passing wsdl to it.

java -cp axis.jar;commons-discovery.jar;commons-logging.jar;jaxrpc.jar;saaj.jar;log4j-1.2.8.jar;xml-apis.jar;xerces.jar;wsdl4j.jar org.apache.axis.wsdl.WSDL2Java   http://appsever_url/axis/services/webserviceDemo?wsdl


This will create all required file at the client side.


6.Generate client

        DemoServiceLocator demoLocator  = new DemoServiceLocator ();

       Demo demo = demoLocator .getWebServiceDemo();

        Demo.call_your_method()


Rahul Ner

No comments: