April 12, 2011

Apache Axis 1.4 - Hello World JWS Web Service Client

In this post, we will create the Web Service Client for the Apache Axis JWS Web Service at this link

1) Create a class HelloWorldClient.java in the src folder of the web application. This class will be a standalone class with a main method and will run in its own JVM


package info.icontraining.ws.client;


import org.apache.axis.client.*;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;


public class HelloWorldClient {


  public static void main(String[] args) throws Exception{
String endpoint = "http://localhost:8080/WebAppName/HelloWorld.jws";


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


call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( "sayHello" );
call.setReturnType( XMLType.XSD_STRING );


String ret = (String) call.invoke( new Object [] { });
System.out.println("Got result : " + ret);
  }
}


2) Run this class as a 'Java Application' (and will not execute on the server)

No comments:

Post a Comment