1.实例1(主要看到[2])
1.1.系统功能:
开发一个计算器服务CalculateService,这个服务包含加(plus)、减(minus)、乘(multiply)、除(divide)的操作。
1.2.开发前准备:
安装Eclipse-jee;
下载最新版本的Axis2,网址http://axis.apache.org/axis2/java/core/download.cgi ,选择Standard Binary Distribution的zip包,解压缩得到的目录名axis2-1.4.1,目录内的文件结构如下:
1.3.开发前配置:
在Eclipse的菜单栏中,Window --> Preferences --> Web Service --> Axis2 Perferences,在Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。(如图)
1.4.开发Web Service:
(1)新建一个Java Project,命名为"WebServiceTest1"
(2)新建一个class,命名为"CalculateService",完整代码如下:
package edu.sjtu.webservice;
/**
* 计算器运算
* @author rongxinhua
*/
public class CalculateService {
//加法
public float plus(float x, float y) {
return x + y;
}
//减法
public float minus(float x, float y) {
return x - y;
}
//乘法
public float multiply(float x, float y) {
return x * y;
}
//除法
public float divide(float x, float y) {
if(y!=0)
{
return x / y;
}
else
return -1;
}
}
(3)在"WebServiceTest1"项目上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“的位