Web services are interoperable , which means a Web service created in Java can be accessed from .NET and vice-versa.
AXIS stands for Apache Extensible Interaction System. It is an open-source project and implements standard JAX-RPC API of Java.
Copy axis directory of d:\axis-1_3\webapps into webapps directory of Tomcat5.
Start Tomcat and test whether the Axis web application is running using http://localhost:8080/axis . Please change port number 8080 with port number that you use for Tomcat in your system.
Test whether Axis has access to all required libraries by using http://localhost:8080/axis/happyaxis.jsp. If any core libraries are missing, make sure you copy them to either WEB-INF/lib directory of Axis or common\lib directory of Tomcat.
public class Hello { public String sayHello( String name) { return "Hello," + name; } }
set AXIS_HOME=d:\axis-1_3 set AXIS_LIB=%AXIS_HOME%\lib set AXISCLASSPATH=.;%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar set classpaht=.;%classpath%;%AXISCLASSPATH% path c:\jdk1.5.0\binYou have to copy xercesimpl.jar and xml-apis.xml or something similar to it must be copied into lib directory of d:\axis-1_3.
HelloClient.java is the client program to access web serice.
import org.apache.axis.AxisFault; 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.namespace.QName; import javax.xml.rpc.ParameterMode; import java.net.URL; public class HelloClient { public static void main(String args[]) throws Exception { Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( "http://localhost:8080/axis/Hello.jws"); call.setOperationName("sayHello"); Object ret = call.invoke( new Object[] {"Srikanth"} ); String res = (String) ret; System.out.println(res); } }
javac HelloClient.java
java HelloClient
You must see message saying Hello,Srikanth. If you get any warning regarding Log4j, ignore them.
Installing a Web service by just copying .jws file into axis directory is called as drop-in deployment.
public class Hello { public String sayHello( String name) { return "Hello," + name; } }
<deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="hello" provider="java:RPC"> <parameter name="className" value="Hello"/> <parameter name="allowedMethods" value="*"/> </service> </deployment>
java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd
import org.apache.axis.AxisFault; 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.namespace.QName; import javax.xml.rpc.ParameterMode; import java.net.URL; public class HelloClient { public static void main(String args[]) throws Exception { Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( "http://localhost:8080/axis/services/hello"); call.setOperationName("sayHello"); Object ret = call.invoke( new Object[] {"Srikanth"} ); String res = (String) ret; System.out.println(res); } }
For further information, refer to axis.apache.org. Also remember axis comes with full documenation in docs directory.
Click Currency Converter Example to see how to create a currency conveter web service and corresponding client.
Keep Learning,