Axis2与Eclipse整合开发Web Service之一:简单的计算服务例子

本文介绍如何使用Eclipse和Axis2开发一个提供基本算术运算的WebService应用,包括加、减、乘、除等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文出处: http://www.blogjava.net/rongxh7
系统功能: 开发一个计算器服务CalculateService,这个服务包含加(plus)、减(minus)、乘(multiply)

、除(divide)的操作。
开发前准备:
1、安装Eclipse-jee;
2、下载Axis2的最新版本Axis2 1.4.1 Release,网址

http://ws.apache.org/axis2/download/1_4_1/download.cgi ,选择Standard Binary Distribution

的.zip包即"axis2-1.4.1-bin.zip"这个文件,解压缩得到的目录名axis2-1.4.1
开发前配置:在Eclipse的菜单栏中,Window --> Preferences --> Web Service --> Axis2

Perferences,在Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。
开发Web Service:
1、新建一个Java Project,命名为"WS_01";
2、新建一个class,命名为"CalculateService",完整代码如下:
package rong.service;

/** *//**
* 计算器运算
* @author rongxinhua
*
*/
public class CalculateService {

/** *//**
* 加法运算
* @param x 被加数
* @param y 加数
* @return x与y的和
*/
public float plus(float x, float y){
return x + y ;
}

/** *//**
* 减法运算
* @param x 被减数
* @param y 减数
* @return x与y之差
*/
public float minus(float x, float y){
return x - y ;
}

/** *//**
* 乘法运算
* @param x 被乘数
* @param y 乘数
* @return x与y的乘积
*/
public float multiply(float x, float y){
return x * y ;
}

/** *//**
* 除法运算
* @param x 被除数
* @param y 除数
* @return x与y的商
*/
public float divide(float x, float y){
return x / y ;
}

}


3、在"WS_01"项目上new --> other,找到"Web Services"下面的"Web Service";
4、下一步(next),在出现的Web Services对象框,在Service implementation中点击"Browse",进入Browse Classes对象框,查找到我们刚才写的写的CalculateService类。点击"ok",则回到Web Service话框。
5、在Web Service对话框中,将Web Service type中的滑块,调到"start service“的位置,将Client type中的滑块调到"Test client"的位置。
6、在Web Service type滑块图的右边有个"Configuration",点击它下面的选项,进入Service Deployment Configuration对象框,在这里选择相应的Server(我这里用Tomcat6.0)和Web Service runtime(选择Apache Axis2)
7、点OK后,则返回到Web Service对话框,同理,Client type中的滑块右边也有"Configuration",也

要进行相应的置,步骤同上。完成后,Next --> next即行。

8、到了Server startup对话框,有个按键"start server"(如下图),点击它,则可启动Tomcat服务器了。

9、等启完后,点击"next -- > next",一切默认即行,最后,点击完成。最后,出现如下界面:(Web Service Explorer),我们在这里便可测试我们的Web服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值