
1、在Eclipse的菜单栏中,Window -->Preferences -->Web Service -->Axis2 Perferences,在Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。
2、新建一个webservice:
(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“的位置,将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即行。进入到Axis2 Web Service Java Bean Configuration,我们选择Generate a default services.xml,如下图所示:
(8)到了Server startup对话框,有个按键"start server"(如下图),点击它,则可启动Tomcat服务器了。
(9)等启完后,点击"next -- >next",一切默认即行,最后,点击完成。最后,出现如下界面:(Web Service Explorer),我们在这里便可测试我们的Web服务。(使用浏览器打开的话使用如下地址:127.0.0.1:19189/wse/wsexplorer/wsexplorer.jsp?org.eclipse.wst.ws.explorer=3)。如下图所示:
第一步:点击菜单栏的”windows“,之后选择”preference“。第二步:找到”server“菜单下的”Runtime Environment“,之后在此页面下点击”add“。
第三步:选择”tomcat6.0“之后,点击”Next“。
第四步:点击”Browse“之后找到”Tomcat“的存储路径,点击”Finsh“即可完成。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)