Developing Java Web services based on Apache Axis2

Source: Internet
Author: User

1. Installation Configuration AXIS2 Environment

1) Download Axis2-1.4.1-war (release WebService) and Axis2-1.4.1-bin.zip (various packages used by WebService call)

Download and post the Axis2.war in the Axis2-1.4.1-war directory to the WebApps of Tomcat.

Release good, visit: http://localhost:8079/axis2/interface is as follows:

2. Developing Web Services

1) Create a Java Web project

2) write the service code

1  Public classSampleservice {2 3      Publicstring getgreeting (string user) {4     return"Hello" +user;5     }6     7      Public intGetPrice () {8     return NewJava.util.Random (). Nextint (100);9     }Ten}

Note: Sampleservice.java cannot have package and import statements in the project

3. Publishing services

Run the project to get the Sampleservice.class file, and then copy it to%tomecat_ehome%\webapps\axis2\web-inf\pojo, if the Web-inf directory is not pojo this directory, Then you have to build one, because in the Axis2 configuration file, you configure the Publish service from the Pojo directory

4. View the service

After the release, launch your Tomcat and visit http://localhost:8079/axis2/services/listServices to see if the release was successful and the interface is as follows:

See that we have just released the Sampleservice instructions successfully, then you can access the service through the following link

Http://localhost:8079/axis2/services/SimpleService/getGreeting?name=bill

Http://localhost:8079/axis2/services/SimpleService/getPrice

5.client Call Service

1) client code for the build service

2) Create a new client project and copy the generated code in

3) Create a new test class

1  Packagecom.test;2 3 Importcom.axis2.client.SampleServiceStub;4 5  Public classSampleservicetest {6     7          Public Static voidMain (string[] args)throwsException {8Sampleservicestub client=Newsampleservicestub ();9         TenSampleservicestub.getgreeting gg=Newsampleservicestub.getgreeting (); OneGg.setuser ("Wangfang"); A          - System.out.println (client.getgreeting (GG). Get_return ()); - System.out.println (Client.getprice (). Get_return ()); the          -     } -}

Note that the jar package under the Axis2-1.4.1-bin\lib is directed in

3) Run View effect

Developing Java Web services based on Apache Axis2

Related Article

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.