Release and invocation of Axis2 WebService

Source: Internet
Author: User

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

2: Configure 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.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, Description the configuration was successful.

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

 Package Org.web.service;   Public class HelloWorldService {      Public string SayHello (string name) {         return "Hello," + name;      } }

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

Next-> Check Skip wsdl,next-> do not fill next-> Select generate the service XML automatically,next->

Fill in the full path of the HelloWorldService class, click Load, show SayHello instructions in the method table below load success, click Next->

Fill in the Output file location and click Finish

3.2.2 Right click on webserviceservice item, refresh. My_service.aar file appears

Put this AAR file under%tomcat_home%\webapps\axis2\web-inf\services. Enter HTTP://LOCALHOST:8080/AXIS2/SERVICES/HELLOWORLDSERVICE?WSDL in the browser to appear, stating that the publication was successful.

4: Generate the client calling code with Eclipse's Web Service client.
4.1: Right-new->other->web services->web service Client at Eclipse's blank workspace, select, click Next-> appear

Service definition fills out the WSDL path http://localhost:8080/axis2/services/HelloWorldService?wsdl,Client type default, Below the slide pull up to the top, click on the server Runtime:tomcat v6.0 server appears diagram:

Select default in Server Runtime, Web service runtime Select Apache Axis2, click OK, go back, click on client project:webserviceclient, show image

In the drop-down list of client project, select the project to which you are hosting code, and this example selects WebServiceClient. Click OK, go back, click Next, go to the next link, then click Finish.

The Org.web.service package appears under the source folder of SRC, with the Helloworldservicecallbackhandler.java and Helloworldservicestub.java files below, the web The APP libraries also has updates, and Axis2-web folders, as well as web-inf updates, appear in the WebContent directory.
4.2: Write WebService calling code.
Create a new client test file in the WebServiceClient project as follows:

 Packageorg.web.client;Importjava.rmi.RemoteException;Importorg.web.service.HelloWorldServiceStub;ImportOrg.web.service.HelloWorldServiceStub.SayHelloResponse; Public classhelloworldclient {/**     * @paramargs *@throwsremoteexception*/     Public Static voidMain (string[] args)throwsremoteexception {String target= "Http://localhost:8080/axis2/services/HelloWorldService"; Helloworldservicestub stub=Newhelloworldservicestub (target); //SayHello provides parameters for WebServiceHelloworldservicestub.sayhello SayHello =NewHelloworldservicestub.sayhello (); Sayhello.setname ("Jackii"); Sayhelloresponse EUR=Stub.sayhello (SayHello); String ReturnVal=Eur.get_return ();    System.out.println (ReturnVal); }}

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

 PackageOrg.web.service;  Public classUser {PrivateString ID; PrivateString name;  PublicString getId () {returnID; }      Public voidsetId (String id) { This. ID =ID; }      PublicString GetName () {returnname; }      Public voidsetName (String name) { This. Name =name; } }

Listservice.java

 PackageOrg.web.service; Importjava.util.ArrayList;Importjava.util.List;  Public classListservice { PublicList<user>getuserlist (user user) {List<User> returnlist =NewArraylist<user>();         Returnlist.add (user);  for(inti=0;i<3;i++) {User user1=NewUser (); User1.setid ("00" +i); User1.setname ("Jack00" +i);         Returnlist.add (user1); }         returnreturnlist; } }

File directory

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

Create Listserviceclient.java

  Packageorg.web.client; Importjava.rmi.RemoteException; Importorg.web.service.ListServiceStub;ImportOrg.web.service.ListServiceStub.GetUserListResponse;ImportOrg.web.service.ListServiceStub.User;  Public classlistserviceclient {/**      * @paramargs *@throwsremoteexception*/      Public Static voidMain (string[] args)throwsremoteexception {String target= "Http://localhost:8080/axis2/services/ListService"; Listservicestub stub=Newlistservicestub (target); Listservicestub.getuserlist getUserList0=Newlistservicestub.getuserlist (); User User=NewUser (); User.setid ("Clienttest"); User.setname ("ClientName");         Getuserlist0.setuser (user); Getuserlistresponse EUR=stub.getuserlist (GETUSERLIST0); User[] Userarray=Eur.get_return ();  for(inti=0;i<userarray.length;i++) {System.out.println ("ID:" +userarray[i].getid () + "Name:" +userarray[i].getname () + "\ n"); }     } }

Run in Java application mode, output:

id:clienttestname:clientnameid:000name:jack000id:001name:jack001id:002name:jack002

Indicates that the call was successful.

This article transferred from: http://www.blogjava.net/tianchijiaozi/archive/2013/03/15/396452.html

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.