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