1. Create WebService
package com.as;
public class Greeting {
public String sayHello(String name) {
return "Hello " + name;
}
}
2. Download axis latest framework and copy the axis directory into webapps in tomcat
3. Add below Entries into “/axis/WEB-INF/server-config.wsdd” in
4. Copy the Greeting into “\axis\WEB-INF\classes\”
5. http://localhost:8080/axis/
You can see few option like list, call and visit. List will show you the available web services.
6. Click List and you should be able to see GreetingService.
7. You can test it via http://localhost:8080/axis/services/GreetingService?method=sayHello&name=Elango
8. Before executing the client, have below jars in classpath
AXIS_ROOT\lib\activation.jar,
AXIS_ROOT\lib\axis.jar
AXIS_ROOT\lib\axis-ant.jar
AXIS_ROOT\lib\commons-discovery-0.2.jar
AXIS_ROOT\lib\commons-logging-1.0.4.jar
AXIS_ROOT\lib\jaxrpc.jar
AXIS_ROOT\lib\log4j-1.2.8.jar
AXIS_ROOT\lib\mail.jar
AXIS_ROOT\lib\saaj.jar
AXIS_ROOT\lib\wsdl4j-1.5.1.jar
TOMCAT_ROOT\lib\xercesImpl.jar
TOMCAT_ROOT\lib\servlet-api.jar
10 Access using client
import java.net.URL;
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
public class GreetingClient {
public static void main(String[] args) {
try{
URL url = new URL("http://localhost:8080/axis/services/GreetingService");
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(url);
Object result = call.invoke("sayHello", new Object[]{"Tendulkar"});
System.out.println(result);
}catch(Exception exception){
exception.printStackTrace();
}
}
}
No comments:
Post a Comment