Use axis to develop WebService

Source: Internet
Author: User
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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.