Release and invocation of Axis2 WebService

Source: Internet
Author: User
Tags wsdl

1: Prepare:
Jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-1902814.html
eclipse:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/sr2/ Eclipse-jee-juno-sr2-win32.zip

tomcat:http://tomcat.apache.org/download-60.cgi
axis2:http://axis.apache.org/axis2/java/core/download.cgi
The official Axis plug-in tool for Eclipse provides the ability to package AAR files and generate client calling code: http://axis.apache.org/axis2/java/core/tools/index.html

Among the service Archive Wizard-eclipse plug-in and code Generator Wizard-eclipse plug-in
Download the completed Software 1.1

Figure 1.12: Configuring the Environment:
2.1: Configure Java Environment variables (do not repeat).
2.1:eclipse AXIS2 Environment configuration: window->perferences->web Services->axis2 perferences->axis2 Runtime->Axis2 Runtime Location,browse Select the axis2-1.6.2 file directory to extract the Axis2-1.6.2-bin.zip from. 2.1.
Figure 2.1
2.2: Install plug-ins: Unzip Axis2-eclipse-codegen-plugin-1.6.2.zip and Axis2-eclipse-service-plugin-1.6.2.zip, put the resulting two jar packages into the Eclipse directory \plugins\, restart Eclipse.
2.3: Configure Tomcat: Unzip Apache-tomcat-6.0.36-windows-x64.zip (do not repeat).
2.4:eclipse in Tomcat configuration: Window->perferences->server->runtime environments added.
3: Release Axis2:
3.1: Unzip axis2-1.6.2-war.zip to get Axis2.war and put it into the WebApps folder of Tomcat decompression directory, launch Tomcat, enter http://localhost:8080/axis2/in the browser, Figure 3.1 appears, indicating that the configuration was successful.
Figure 3.1
3.2: Publish the Web Service with Eclipse's Axis2 plugin.
3.2.1 New dynamic Web Project in Eclipse, named Webserviceservice. Write a simple WebService server code
1 package org.web.service;
2 
3 class helloworldservice {
4     public string  sayhello (string name) {
5          return  "Hello,"  + name;
6     }
7 }
8  3.2.2 in the blank workspace of Eclipse, right-new->other, in the popup dialog box, locate the Axis2 Service archiver, double-click Select the class path for the project where the HelloWorldService is located, 3.2
Figure 3.2
Next-> Check Skip wsdl,next-> do not fill next-> Select generate the service XML automatically,next->
Figure 3.3
such as 3.3 fill inhelloworldservice the full path of the class, click Load, in the following method table appears SayHello description load succeeded, click Next->
Figure 3.4
     fill in the Output file location and click finish,3.4.
        3.2.2     Right click on webserviceservice item to refresh. The My_service.aar file appears, 3.5.
Figure 3.5
    Place this AAR file under%tomcat_home%\webapps\axis2\web-inf\services. Enter HTTP://LOCALHOST:8080/AXIS2/SERVICES/HELLOWORLDSERVICE?WSDL in the browser, and figure 3.6 shows that the publication was successful.
Figure 3.6
4: Generate the client calling code with Eclipse's Web Service client.
    4.1: Right-click New->other->web services->web Service Client at the blank workspace of Eclipse, select, Click next-> appear figure 4.1 Figure 4.1
Service definition fill out the published WSDL path http://localhost:8080/axis2/services/HelloWorldService? Wsdl,client type Default, the following slide is pulled up to the top, click Server Runtime:tomcat v6.0 server appears figure 4.2:

Figure 4.2
Select default in Server Runtime, Web service runtime Select Apache Axis2, click OK, return to Figure 4.1, click on client project:webserviceclient, figure 4.3 figure 4.3
In the drop-down list of client project, select the project to which you are hosting code, and this example selects WebServiceClient. Click OK, return to Figure 4.1, click Next, go to the next link, then click Finish.
, Figure 4.4
4.4, source in SRC Folder appears under the Org.web.service package, below the Helloworldservicecallbackhandler.java and Helloworldservicestub.java files, Web App Libraries also has updates, in the WebContent directory also appears Axis2-web folder, as well as Web-inf and other updates.
4.2: Write WebService calling code.
Create a new client test file in the WebServiceClient project as follows:

1Package org.web.client;
2
3Import java.rmi.RemoteException;
4
5Import org.web.service.HelloWorldServiceStub;
6Import Org.web.service.HelloWorldServiceStub.SayHelloResponse;
7
8PublicClass Helloworldclient {
9
10/**
11*@paramArgs
12*@throwsRemoteException
13*/
14PublicStaticvoid Main (string[] args)Throws RemoteException {
String target = "Http://localhost:8080/axis2/services/HelloWorldService";
Helloworldservicestub stub =New Helloworldservicestub (target);
17//SayHello provides parameters for webservice
18          helloworldservicestub.sayhello sayhello = new  Helloworldservicestub.sayhello ();
19         sayhello.setname (" Jackii ");
20         sayhelloresponse  eur = stub.sayhello (SayHello);
21         string  Returnval = eur.get_return ();
22         system.out.println ( ReturnVal);
23     }
24 
25 }

Running the above code run As->java application, output:

Hello,jackii

Indicates that the call was successful.
5: Reference Document http://wenku.baidu.com/view/12501ed7195f312b3169a54b.html
6: The server receives the parameter JavaBean, returns the list sample:
6.1: Create the service. New User.java

1Package org.web.service;
2
3PublicClass User {
4Private String ID;
5private String name;
6Public String getId () {
7return ID;
8}
9Publicvoid SetId (String id) {
10This.id = ID;
11     }
12     public  String getname ()  {
13          return name;
14     }
15     public < Span style= "color: #0000ff;" >void setname (string name)  {
16          this.name = name;
17&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}
18&NBSP;}
19&NBSP; Listservice.java
1Package org.web.service;
2
3Import java.util.ArrayList;
4Import java.util.List;
5
6PublicClass Listservice {
7Public list<user> getuserlist (user user) {
8 list<user> returnlist =New Arraylist<user> ();
9 Returnlist.add (user);
10Forint i=0;i<3;i++) {
One User user1 =new user ();
12              user1.setid ("xx" +i);
13              user1.setname ("jack00" +i);
14              returnlist.add (user1);
15&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}
16         return returnlist;
17&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}
18&NBSP;}

File directory 6.1:
Figure 6.1
Republish the service according to 3.2 instructions (Figure 3.4Output File name re-name)
6.2: Create the client calling code, the same as 4. Get the two files shown in Figure 6.2 Listservicestub.java and Listservicecallbackhandler.java
Figure 6.2
Create Listserviceclient.java

1Package org.web.client;
2
3Import java.rmi.RemoteException;
4
5Import org.web.service.ListServiceStub;
6Import Org.web.service.ListServiceStub.GetUserListResponse;
7Import Org.web.service.ListServiceStub.User;
8
9PublicClass Listserviceclient {
10
11/**
12*@paramArgs
13*@throwsRemoteException
14*/
15PublicStaticvoid Main (string[] args)Throws RemoteException {
String target = "Http://localhost:8080/axis2/services/ListService";
Listservicestub stub =New Listservicestub (target);
Listservicestub.getuserlist getUserList0 =New Listservicestub.getuserlist ();
User User =New User ();
User.setid ("Clienttest");
User.setname ("ClientName");
Getuserlist0.setuser (user);
Getuserlistresponse EUR = Stub.getuserlist (GETUSERLIST0);
user[] Userarray = Eur.get_return ();
(int i=0;i<userarray.length;i++) {
SYSTEM.OUT.PRINTLN ("ID:" +userarray[i].getid () + "Name:" +userarray[i].getname () + "\ n");
27}
28}
}

Run in Java application mode, output:

1 Id:clientTestname:ClientName
2
3 id:000name:jack000
4
5 id:001name:jack001
6
7 id:002name:jack002

Indicates that the call was successful.

Release and invocation of Axis2 WebService

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.