使用Axis2-1.6.1实现第一个Web Service

使用Axis2-1.6.1实现第一个Web Service

教程是对51CTO视频教程的文字总结及个人实践
首先下载Axis2,我下载Binary Distribution的axis2-1.6.1-bin.zip和WAR Distribution的axis2-1.6.1-war.zip。

安装

将axis2-1.6.1-war.zip解压得到的axis2.war文件复制到Tomcat安装目录下webapps文件夹中,启动Tomcat即可。Tomcat安装目录下webapps文件夹中生成了axis2文件夹。

编写Web Service类

编写一个SimpleServicce类:

public class SimpleService{
    public String getGreeting(String name){
        return "hello " + name;
    }
    public int getPrice(){
        return new java.util.Random().nextInt(100);
    }
}

打开cmd命令窗口,使用javac SimpleService.java命令编译得到SimpleService.class文件。

发布Web Service

将Web Service类编译生成的.class文件,即上一步得到的SimpleService.class文件复制到Tomcat安装目录\webapps\axis2\C:\Tomcat\webapps\axis2\WEB-INF\pojo文件夹中,没有pojo文件夹请自行创建。不用重启Tomcat该SimpleService已经热发布成功。可以使用如下URL查看已经发布的Web Service列表:
http://localhost:8080/axis2/services/listServices
点击SimpleService可以看到关于该Web Service的wsdl描述我的本地地址为http://localhost:8080/axis2/services/SimpleService?wsdl
其中<xs:element name="getGreeting">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

定义了getGreeting方法参数name为args0,接下来可以使用URL测试getGreeting方法:http://localhost:8080/axis2/services/SimpleService/getGreeting?args0=world
得到如下结果:

<ns:getGreetingResponse xmlns:ns="http://ws.apache.org/axis2">
<return>hello world</return>
</ns:getGreetingResponse>

下一篇将介绍使用java RPC方法调用Web Service和wsdl2java命令的使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值