//Use the import statement to tell what packages these classes
//can be found in

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import javax.xml.rpc.ParameterMode;
import java.net.URL;

public class ArithmeticClient
{
   //A main method is the entry point for this program  

   public static void main(String[] args) throws Exception
   {
      //The Options class is a container for the
      // inputs on the command line
      Options options = new Options(args);
      
      //An endpoint is the URL of the web service
      String endpointString = "http://localhost:" +
        options.getPort() + "/axis/ArithmeticProcessor.jws";

      //The args are the command line arguements
      args = options.getRemainingArgs();

      //check to see if the right number of args were passed in
      if (args == null || args.length != 3 )
      {
         System.err.println("Wrong number of args");
         return;
      }

      //The first arg is the name of the method to call
      String methodName = args[0];

      //The other two args are the values to be combined
      Integer i1 = new Integer(args[1]);
      Integer i2 = new Integer(args[2]);


      //The Service object will contain a handle 
      //to the web service
      Service service1 = new Service();

      //The Call object will contain a handle to one call
      // to the web service
      Call    callOne    = (Call)service1.createCall();

      //The endpoint is really a URL
      URL endpoint = new URL(endpointString);

      //tell the Call object what endpoint to access
      callOne.setTargetEndpointAddress(endpoint);

      //tell the Call object what method to call
      callOne.setOperationName(methodName);

      //Set up the parameter types and the return type
      callOne.addParameter("op1", XMLType.XSD_INT,
                                   ParameterMode.IN);
      callOne.addParameter("op2", XMLType.XSD_INT,
                                    ParameterMode.IN);
      callOne.setReturnType( XMLType.XSD_INT );

      //make the call with the invoke() method
      Integer ret = (Integer)callOne.invoke(
                             new Object[] { i1, i2 });

      //Print the result on the screen
      System.out.println("The result is : "  + ret);
   }
}
