1、Axis2的下载和安装
首先可以下载如下两个zip包:axis2-1.6.1-bin.zip
axis2-1.6.1-war.zip
其中 axis2-1.6.1-bin.zip文件中包含了Axis2中所有的jar文件,
axis2-1.6.1-war.zip文件用于将WebService发布到Web容器中。
将axis2-1.6.1-war.zip文件解压到相应的目录,将目录中的axis2.war文件放到<Tomcat安装目录>\webapps目录中,
并启动Tomcat,在浏览器地址栏中输入如下的URL:
http://localhost:8080/axis2/
如看到axis2的主页面则安装成功。
2、简单的pojo方式(无需配置):
在Axis2中不需要进行任何的配置,就可以直接将一个简单的POJO发布成WebService。其中POJO中所有的public方法将被发布成WebService方法。示例代码如下:
编译HelloService类后,将HelloService.class文件放到<Tomcat安装目录>\webapps\axis2\WEB-INF\pojo目录中(如果没有pojo目录,则建立该目录)。现在我们已经成功将HelloService类发布成了WebService。
在浏览器地址栏中输入如下的URL:
http://localhost:8080/axis2/services/listServices
在浏览器地址栏中输入如下的两个URL来分别测试sayHelloToPerson和sayHello方法:
1.http://localhost:8080/axis2/services/HelloService/sayHello
2.http://localhost:8080/axis2/services/HelloService/sayHelloToPerson?name=bill
页面显示如下结果:
- <ns:sayHelloToPersonResponse xmlns:ns="http://ws.apache.org/axis2">
- return>hello,bill</>
- ns:sayHelloToPersonResponse>