Axis is an open source web service engine of Apache. It is currently one of the most mature open-source Web service engines. The following describes how to use axis to develop your web service.
1. Install
Using tomcat4.1 as the server, the following describes how to install axis:
1. decompress the downloaded package and copy the axis directory in the package to the webapps directory under the Tomcat directory;
2. Copy the class files under the axis/WEB-INF/lib directory to the common/lib directory under the Tomcat directory;
3. Restart tomcat;
4. Access http: // localhost: 8080/axis/happyaxis. jsp. If yes, the installation is successful;
2. Develop WebService
A. Compile a common class file as follows: // File Name: Test. Java
Import Java. util. * ;
Public Class Test {
// Fields
Private String name = " Gaga " ;
Private Int Age = 20 ;
Private LIST ITEMS = New Arraylist ();
// Method at here.
Public String getname () {
ReturnName;
}
Public Int Getage () {
ReturnAge;
}
Public List getitems () {
ReturnItems;
}
}
Copy this file (test. Java) to the axis directory and rename it test. JWS;
B. Access http: // localhost: 8080/axis/test. JWS, and axis will compile the file and deploy it to the system;
Now you can develop the web service client.ProgramNow;
3. Develop client programs
The following is the client program: Import Org. Apache. axis. Client. * ;
Import Org. Apache. axis. Client. call;
Import Org. Apache. axis. Client. Service;
Import Javax. xml. namespace. QNAME;
Public Class Testwebservice {
Public Static Void Main (string ARGs []) {
System. Out. println ( " Start invoking. " );
Try {
String endpoint =
" HTTP: /localhost: 8080/axis/test. JWS " ; // The file you wrote
Service = New Service ();
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress ( New Java.net. URL (endpoint ));
Call. setoperationname ( " Getage " ); // Enter the name of the method you want to call
Int RET = Integer. parseint (( "" + Call. Invoke ( New Object [] {} )));
System. Out. println (RET );
} Catch (Exception E) {
System. Err. println (E. tostring ());
}
System. Out. println ( " Finished the invoking. " );
}
}
It's so easy to encapsulate business calls in a server program and then deploy them.
4. Resources
Http://ws.apache.org/axis/