This page provides different components, and deployment scripts for a sample web service.

The web services covered are RPC style.

Following is the code for the web service implementation

 

  package webservice.simple;

 

 

/**

 * Provides a few basic mathematical functions.

 * This class is the heart of the webservice,doing the

 * actual computations.

 */

public class MathService{

     

      /**

       * Adds two integers.

       *

       * @param num1 first operand of the add operation.

       * @param num2 second operand of the add operation.

       * @return returns the sum of num1 and num2.

       */

      public int addInt(int num1,int num2){

        return (num1+num2);

      }

 

    /**

     * Method designed to show, how exceptions map to SOAP faults.

     * @param num1 Is an integer argument.

     * @throws Exception Generic exception, which is thrown intentionally.

     */

    public void throwAnException(int num1)throws Exception{

      throw new Exception("Intentionally thrown Exception");

    }

}

 

 

 

 

Following is the client code required to access the above web service

 

package webservice.simple;

 

import org.apache.axis.AxisFault;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import org.apache.axis.utils.Options;

 

import javax.xml.namespace.QName;

import javax.xml.rpc.ParameterMode;

 

import org.apache.axis.message.SOAPHeaderElement;

 

public class Client

{

    public static void main(String [] args) throws Exception

    {

        Options options = new Options(args);

       

            Service  service = new Service();

            Call     call    = (Call) service.createCall();       

        Integer result = null;

       

        try {

                  call.setTargetEndpointAddress( new java.net.URL(options.getURL()) );          

            //Plain call           

//                call.setOperationName(new QName("Calculator", "addInt"));

//                call.addParameter( "arg1", org.apache.axis.encoding.XMLType.XSD_INT, ParameterMode.IN );

//                call.addParameter( "arg2", org.apache.axis.encoding.XMLType.XSD_INT, ParameterMode.IN );

//                call.setReturnType( org.apache.axis.encoding.XMLType.XSD_INT);

//                result = (Integer) call.invoke( new Object[] {new Integer(2),new Integer(4)} );

//                                 

//                //Add Header element

//                SOAPHeaderElement header  = new SOAPHeaderElement("abc","transactionId","QF12A0X");

////              public SOAPHeaderElement(java.lang.String namespace,

////                                                  java.lang.String localPart,

////                                                  java.lang.Object value)

//                call.addHeader(header);            

//                //result = (Integer) call.invoke( new Object[] {new Integer(2),new Integer(4)} );

                 

//                //Fault

                  call.setOperationName(new QName("Calculator", "throwAnException"));

                  call.addParameter( "arg1", org.apache.axis.encoding.XMLType.XSD_INT, ParameterMode.IN );

                  Object fltRslt =  call.invoke( new Object[] {new Integer(3)} );   

                 

        } catch (AxisFault fault) {

            System.out.println("SOAP Fault : " + fault);

        }

       

        System.out.println(result);

    }

}

 

 

 

ANT build file to deploy and undeploy the webservice  to/from AXIS SOAP seraver

Based on deployment or undeployment , just change the value of property wsddFile

 

<project default="deployUndeploy">

  <property name="JAVA_HOME" value="C:\j2sdk1.4.2_02"/>

  <property name="AXIS_HOME" value="C:\axis-1_2alpha"/>

  <property name="host_port" value="localhost:8080"/>

  <property name="wsddFile" value="undeploy.wsdd"/>

 

      <path id="compileClasspath">

            <pathelement location="${JAVA_HOME}\lib"/>

 

            <fileset dir="${AXIS_HOME}\lib">

                  <include name="*.jar"/>

            </fileset>

 

      </path>

 

  <target name="deployUndeploy">

         <java classname="org.apache.axis.client.AdminClient"

               classpathref="compileClasspath"

             fork="true"

          >

              <arg value="${wsddFile}"/>

              <arg value="-lhttp://${host_port}/axis/services/AdminService"/>

         </java>

  </target>

 

</project>

 

 

Sample deployment file – deploy.wsdd

 

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

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

        <parameter name="className" value="webservice.simple.MathService"/>

        <parameter name="allowedMethods" value="addInt throwAnException"/>       

    </service>

</deployment>

 

 

Sample wsdd(webservice deployment descriptor) file undeploying the webservice from AXIS

 

<undeployment name="test" xmlns="http://xml.apache.org/axis/wsdd/">

  <service name="OrderProcessor"/>

</undeployment>

 

 

If your webservices have a user defined type as a parameter or return type, then you will be required define

a bean mapping for serialization and deserialization.Please refer to online AXIS User Guide for details about

specifying the bean mapping.