Axis2 and eclipse integrated Web Service Development

Source: Internet
Author: User

System Function: Develop a calculator service calculateservice, which includes plus, minus, and multiplication)

Divide.

Preparations before development:
1. Install eclipse-jee;
2. download the latest version of axis2 1.4.1 release.

Http://ws.apache.org/axis2/download/1_4_1/download.cgi
, Select standard binary Distribution

The. Zip package is the "axis2-1.4.1-bin.zip" file, decompress the obtained directory name axis2-1.4.1, the file structure in the directory as shown in

Below:

Configure and install Tomcat

Install Tomcat

To install Apache Tomcat, decompress the Downloaded archive file and put it in the directory. I put it in my C:/apps directory for future search. So far, this is enough. Use the eclipse shown later to start Tomcat.

 



Back to Top

Create a new web project

From Eclipse IDE, selectFile> New> Project
View the Project Wizard. In the Wizards box, enterWeb
The new project window filters out the Wizard to display only the matching items. Using this method, you can easily find the wizard without traversing each item.

Select from ListDynamic Web project
.
We need to use standard web Project Wizard to create a static HTML web project. Although you can also use it technically
Tomcat runs static Web sites, but Web servers, such as Apache web server, are more suitable for static content.
Web servers designed specifically to serve static pages have less overhead and are specially optimized for this purpose.

Target Database

InTarget Runtime
As shown in <none>, 4, you must clickNew
OpenNew target runtime wizard
. Select Apache Tomcat v5.5, 5 from the Apache folder, and then clickNext
.

Figure 4. Create a new dynamic web project


Figure 5. Create a new Server Runtime Library


Now, you can name this Runtime Library, of course, retain the default name of Apache Tomcat v5.5. ClickBrowse
To find the basic folder for Apache Tomcat configuration (my files are C:/apps/Apache-Tomcat-5.5.20, 6 ).
). If there are no special reasons, we recommend that you do not change it. Retain the IBM Java Runtime Environment (JRE) version as the workbench's default
JRE. Enter a valid directory and clickFinish
Create a Runtime Library configuration.

Figure 6. Define the server location


Very complicated configuration, and you want to cut it down to a simple

You also need to select whether to convert to J2EE perspective. I always choose yes, because this perspective contains some useful views, such as the servers view, which can help you start and stop tomcat in the future. SelectWindow> show View
You can open the servers view.

Axis configuration before development: In the eclipse menu bar, window --> preferences --> Web Service --> axis2

Perferences: In the axis2 runtime location, select the location where the axis2 package is decompressed. After setting it, click "OK. (

)

Develop Web Service:
1. Create a New Java project named "ws_01 ";
2. Create a new class named "calculateservice". The complete code is as follows:

Package
Rong. Service;


/***/
/**


* Calculator operation

*
@ Author
Rongxinhua

*

 
*/



Public
 
Class
Calculateservice

{




/***/
/**


* Addition operation

*
@ Param
X Increment

*
@ Param
Y Addition

*
@ Return
Sum of X and Y


*/




Public
 
Float
Plus (
Float
X,
Float
Y)

{


Return
X
+
Y;

}






/***/
/**


* Subtraction

*
@ Param
X subtrahend

*
@ Param
Y

*
@ Return
Difference between x and y


*/




Public
 
Float
Minus (
Float
X,
Float
Y)

{


Return
X
-
Y;

}






/***/
/**


* Multiplication

*
@ Param
X Multiplier

*
@ Param
Y Multiplier

*
@ Return
Product of X and Y


*/




Public
 
Float
Multiply (
Float
X,
Float
Y)

{


Return
X
*
Y;

}






/***/
/**


* Division operation

*
@ Param
X dividend

*
@ Param
Y Divisor

*
@ Return
Vendors of X and Y


*/




Public
 
Float
Divide (
Float
X,
Float
Y)

{


Return
X
/
Y;

}




}

 

3. In the "ws_01" Project New --> Other, find "Web Service" under "Web Services ";

4. Next, In the displayed web services object box, click "Browse" in service implementation to enter

In the Browse classes object box, find the calculateservice class we just wrote. (For example ). Click "OK" to return

Web Service dialog box.

5. In the Web Service dialog box, adjust the slider in the Web service type to the "Start Service" position and set the client

Adjust the slider in type to the "test client" position.

6. There is a "configuration" on the right of the web service type slider chart. Click the options below it to enter the service

In the deployment configuration object box, select the corresponding server (tomcat6.0 here) and Web Service

Runtime (select Apache axis2), for example:

7. Click OK to return to the Web Service dialog box. Similarly, "configuration" is also displayed on the right of the slider in client type.

The steps are the same as above. After completion, next --> next is the line.

8. In the server startup dialog box, click Start server. Click it to start the Tomcat server.

.

9. After the startup is complete, click "next --> next". Everything is done by default. Finally, click Finish. Finally, the following page is displayed: (Web

Service Explorer), we can test our web service here.

10. The test is relatively simple. For example, we select a "plus" operation, and enter 2 in the input box of X.

Enter 3 in the input box and click "go". The result 5.0 is displayed in the Status column. The tests for other methods are similar.

Here, the server and client of the web service integrated with axis2 and eclipse are successfully developed. Try it too!

Related Article

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.