如何eclipse创建一个webservice service

如题所述

在eclipse创建webservice的方法:

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)。


具体的还可以看下面地址参考。

http://zhidao.baidu.com/link?url=GqKfOxxROj960DMFVe0-NsqK-Y14nrprb0-ivRCfK4A5nmC40JxpGHWHDdOfYjlS-C7BUolXI4Db5ExpNZ8HKVDehrwdtFtA7EaoVRQuRsC

温馨提示:答案为网友推荐,仅供参考
相似回答