Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6539575
  • 博文数量: 915
  • 博客积分: 17977
  • 博客等级: 上将
  • 技术积分: 8846
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-26 09:59
个人简介

一个好老好老的老程序员了。

文章分类

全部博文(915)

文章存档

2022年(9)

2021年(13)

2020年(10)

2019年(40)

2018年(88)

2017年(130)

2015年(5)

2014年(12)

2013年(41)

2012年(36)

2011年(272)

2010年(1)

2009年(53)

2008年(65)

2007年(47)

2006年(81)

2005年(12)

分类: 系统运维

2011-05-14 11:42:44

[图解教程] Axis2与Eclipse整合开发Web Service之一:简单的计算服务例子
时间:2009-07-02 16:55    来源:未知    作者:admin
核心提示:系统功能: 开发一个计算器服务CalculateService,这个服务包含加(plus)、减(minus)、乘(multiply) 、除(divide)的操作。 开发前准备: 1、安装Eclipse-jee; 2、下载Axis2的最新版本Axis2 1.4.1 Release,网址

系统功能: 开发一个计算器服务CalculateService,这个服务包含加(plus)、减(minus)、乘(multiply)

、除(divide)的操作。

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

,选择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",完整代码如下:

  1. package rong.service;   
  2.   
  3. /** *//**  
  4.  * 计算器运算  
  5.  * @author rongxinhua  
  6.  *  
  7.  */  
  8. public class CalculateService {   
  9.        
  10.     /** *//**  
  11.      * 加法运算  
  12.      * @param x 被加数  
  13.      * @param y 加数  
  14.      * @return x与y的和  
  15.      */  
  16.     public float plus(float x, float y){   
  17.         return x + y ;   
  18.     }   
  19.        
  20.     /** *//**  
  21.      * 减法运算  
  22.      * @param x 被减数  
  23.      * @param y 减数  
  24.      * @return x与y之差  
  25.      */  
  26.     public float minus(float x, float y){   
  27.         return x - y ;   
  28.     }   
  29.        
  30.     /** *//**  
  31.      * 乘法运算  
  32.      * @param x 被乘数  
  33.      * @param y 乘数  
  34.      * @return x与y的乘积  
  35.      */  
  36.     public float multiply(float x, float y){   
  37.         return x * y ;    
  38.     }   
  39.        
  40.     /** *//**  
  41.      * 除法运算  
  42.      * @param x 被除数  
  43.      * @param y 除数  
  44.      * @return x与y的商  
  45.      */  
  46.     public float divide(float x, float y){   
  47.         return x / y ;   
  48.     }   
  49.   
  50. }  

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、测试比较简单,例如,我们选择一个"plus"的Operation,出现下图,在x的输入框中输入2,在y的

输入框中输入3,点击"go",便会在status栏中显示结果5.0。其他方法的测试也类似。

到这里用Axis2与Eclipse整合开发的Web Service的服务端和客户端就成功了。你也试试吧!
   转自: http://www.blogjava.net/rongxh7


阅读(676) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~