An axis2 WebService helloword example

Source: Internet
Author: User
Tags wsdl

An axis2 WebService helloword example
1. Download (standard distribution) and (War distribution) from the site)

2. Create a Java project in eclipse. For example, create a new package stub for axisservice and create a Java file helloaxis2 in the package. The content is as follows:

Package stub;

Public class helloaxis2 {
Public String echo (string value) {system. Out. println (">>>> service helloworldservice:" + value + ""
+ New java. util. Date (). tolocalestring ());
Return value;

3. Create a folder META-INF under the project and create a services. XML in it with the following content:

<Parameter name = "serviceclass" locked = "false">
Stub. helloaxis2
<Operation name = "Echo">
Class = "org. Apache. axis2.rpc. Receivers. rpcmessagereceiver"/>

4. package it into *. AAR method:

Select the entire stub package, select the services. xml file, right-click the export and select JAR file. Name it helloaxis2.aar finish.

Helloaxis2.aar exists in the workspace directory of Eclipse.

5. Next, go to Tomcat. decompress the downloaded axis2.war file to Tomcat 5.5's webapps and start Tomcat 5.5.

Type http: // 8080/axis2/(default port). If the welcome interface appears, OK.

6. Go to the administration page and enter the admin password axis2.

Upload the service helloaxis2.aar file just created on the upload service page, and then the service helloaxis2 will be available.

The following information is displayed on the available services page, indicating that the service is OK.

Service EPR: http: // 8080/axis2/services/helloaxis2
Service rest EPR: http: // 8080/axis2/rest/helloaxis2

Service Description: NULL
Http: // 8080/axis2/services/helloaxis2? The WSDL file is displayed.

7. Run the CMD command to enter the unzipping package and execute:

Wsdl2java. Bat-Uri http: // localhost: 8080/axis2/services/helloaxis2? WSDL-o f:/-P stub

A src/stub package is generated in F:/, and two Java (helloaxis2callbackhandler. Java helloaxis2stub. Java) are copied to the project of another test client for testing.

Add a Java test class testhelloaxis2. The content is as follows:

Package test;

Import stub. hwsstub;
Import stub. hwsstub. echoresponse;

Public class testhws {

Public static void main (string [] ARGs) throws exception {
Hwsstub stub = new hwsstub ();
Hwsstub. Echo Request = new hwsstub. Echo ();

Request. setvalue (">>>>> client OK:" + new java. util. Date (). tolocalestring ()
+ "Axis2 Web Service .........");
Echoresponse response = stub. Echo (request );
System. Out. println ("response:" + response. get_return ());

Test results:
[10:31:10] [info] deploying module: metadataexchange-file:/D:/axis2/axis2-1.4.1/lib/mex-1.4.1.jar-at Org. apache. axis2.deployment. moduledeployer. deploy (moduledeployer. java: 75)

Response: >>>>>> client OK: 2008-12-10 10: 31: 10axis2 Web Service .........

Test with IE browser

Http: // localhost: 8080/axis2/services/helloaxis2/Echo? Value = test


- < NS: echoresponse Xmlns: NS =" Http: // stub " >   < NS: Return > Test </ NS: Return >   </ NS: echoresponse >


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: 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.