Creating a dynamic Array Generator Web Service using AXIS

I just happened to create a webservice and a client using ASIX for a web service class. As I know that in the environment it is difficult to get things to work and minor issues can halt the process. I am posting a simple Service, Client and my configurations just in case they are helpful to any one. In my environment TOMCAT is the web container and I compile it with AXIS jar files in my classpath, deploy.wsdd is used for deployment:
I use the variable %AXISCLASSPATH% which is set in my environment variables to following:


AXIS_LIB is set to: %AXIS_HOME%\lib
AXIS_HOME is set to : C:\axis-1_4

Step 1 is to code the service: In the given scenario the service expects an integer passed to it in the GetDynamicArrayOfRandomNumbers method and it will return an array with the number of elements equal to the number passed in. It will populate the array with random numbers.

import java.util.Random;

 * @author Muhammad Asad Siddiqi
 * 06/13/2009
 *  This class is used as the web service and the .class has to be copied under Tomcat/axis/webapps
 *  deploy.wsdd has to be used for deployment

public class DynamicArrayGeneratorService
     * This is the remote method that would be called by the client
    public int [] GetDynamicArrayOfRandomNumbers (int nArraySize) throws Exception
        int []arrRandomNumbers = new int[nArraySize];
        for (int nCount=0; nCount < nArraySize; nCount++)
            Random randomGenerator = new Random();
            arrRandomNumbers[nCount] = randomGenerator.nextInt((nCount * 4) + 10);           
        return arrRandomNumbers;       

Step 2: Compiling the service can be done by running the following commands from where your code is:

javac -classpath %AXISCLASSPATH%

Step 3 is coding the client, I am copying and pasting the code for the client below:

import java.lang.*;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;

 * @author Asad Siddiqi
 * Assignment # 2 Web services
 * This class is the client for the service running on localhost
public class DynamicArrayGeneratorClient
 public static void main(String args[])
   int nSizeToReturn = 0;
   if ( args == null || args.length != 1 )
    System.out.println(“The client utility has to pass in the exactly 1 parameter [size of the array]”);
   nSizeToReturn = Integer.parseInt(args[0]);   

   // Create an instance of the service
          Service serArrayGenerator = new Service();
   // Create an instance of the Call to call the method
   Call call = (Call) serArrayGenerator.createCall();
   // Set the Address for connection
   // Specify the method to call
   // Call the remote method
   int [] arrReturned = (int[]) call.invoke(new Object [] {new Integer(nSizeToReturn)});

   // Print the output

   for (int i = 0; i < arrReturned.length; i++)
     catch( Exception e )
   // Error occured during processing
   System.out.println(“Error Occured during processing …”);

Step 4: Compiling the Client can be done by executing the following command from the same directory as your client code:

javac -classpath %AXISCLASSPATH%

Step 5 : In your command prompt navigate to the directory where your deploy.wsdd file is located. Once you are in the right directory execute the following command:

java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

Step 6: The client can be executed by again changing the directory to where the .class files were generated for the client and executing the following command:

java -cp .;%AXISCLASSPATH% edu.jhu.webservices.Siddiqui.Asad.DynamicArrayGeneratorClient 20

I am also posting the contents of deploy.wsdd file:

<deployment name=”hw2″ xmlns=”

  <service name=”DynamicArrayGeneratorService” provider=”java:RPC”>
    <parameter name=”className” value=”DynamicArrayGeneratorService”/>
    <parameter name=”allowedMethods” value=”GetDynamicArrayOfRandomNumbers”/>
    <parameter name=”wsdlServicePort” value=”GetDynamicArrayOfRandomNumbers”/>


If you find it useful or I was able to help you out or you have a question, feel free to comment and I will make sure to reply. Being a .Net developer this was a real pain and it sucks, I just posted to help anyone in the same boat as me.


Leave a comment

Filed under 1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s