First, prepare
1. Download Axis2, Eclipse plugin
Axis2-1.6.2-war.zip:
Http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-war.zip
Axis2-1.6.2-bin.zip:
Http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip
Axis2-eclipse-codegen-plugin-1.6.2.zip:
Http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-codegen-plugin-1.6.2.zip
Axis2-eclipse-service-plugin-1.6.2.zip:
Http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-service-plugin-1.6.2.zip
2. Deployment
Unzip the Axis2-1.6.2-war.zip to deploy Axis2.war to Tomcat and access the http://localhost:8080/axis2/
3. Install Eclipse Plugin
Unzip the plugin and copy the file directly into the plugins directory. Open Eclipse, right-click in the Package Explorer---> select new---->other
Second, the development of the service side
1. Build a Java Project project with the name "MyService" and create a service class
Java code
- Package com.my.server;
- Public class Simpleserver {
- Public string Simplemethod (string name) {
- return name + "said: Take the road of others, let others have no way to go." ";
- }
- }
1. Right-click in the Eclispe package Explorer and select New--->other ...----->axis2 Service archiver.
2. Click Next to enter the class Selection page and select the folder in the class file location selection box, which is the root directory where the Java.class file is stored.
3. Click Next to go to the Select WSDL file and select Skip WSDL.
4. Click Next to go to the Select Jar File page. (no external jar is used, click Next to skip directly)
5. Click Next to go to the Select XML page. Tick generate the service XML automatically.
6. Click Next to enter the Generate XML file page. In the service name, fill in the name (Simpleserver) from which you want to publish the class name (full path), and then click the Load button.
7. Click Next to enter the output artiver file page, select the path you want to output in the outputs file location, and enter the name of the Artiver file in output file name (simpleserver).
8, click Finish, if you see the following screen, congratulations, the service released successfully.
9. Publish the AAR file into Tomcat.
Copy the generated AAR files to the service directory location in the AXIS2 project in the Tomcat directory.
10, start Tomcat, enter HTTP://LOCALHOST:8080/AXIS2 in the Address bar, you will see Axis2 Welcome screen.
Third, the development of the client
Place the Dynamic Web project item with the name client.
1. Right-click in the Eclispe package Explorer and select New--->other in the menu ...----->axis2 Code Generator.
2. Click Next to enter and choose to generate Java files from the WSDL file.
3. Click Next and select the WSDL file.
4. Click Next to enter the Settings page, with the default settings.
5. Click Next to select the path of the output file.
6, click Next, if you see this page, has generated code success.
7. Introduction of Jar Package (\axis2-1.6.2\lib).
8, write the test method call service.
Importcom.my.server.SimpleServerStub; Public classSimpleClient { Public Static voidMain (string[] args)throwsexception{//Initialize pile filesSimpleserverstub stub =Newsimpleserverstub (); //initializes the Simplemethod method. Simpleserverstub.simplemethod request =NewSimpleserverstub.simplemethod (); //call the SetName method of Simplemethod. Request.setname ("ZT"); // System.out.println (Stub.simplemethod (Request). Get_return ());} }
Reference: http://blog.csdn.net/yangsen251024/article/details/7043043
Develop WebService with Axis2