准备工作

1、下载:axis2-1.5.4-bin.zip,axis2-1.5.4-war.zip 下载地址:http://axis.apache.org/axis2/java/core/
2、环境变量设置
AXIS2_HOME E:\research\axis2-1.5.4-bin\axis2-1.5.4
JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
3、axis2-1.5.4-war.zip解压,将压缩包内的axis2.war部署到%TOMCAT-HOME%/webapps下,启动tomcat,访问http://localhost:8085/axis2/看是否正常。

点击Service会进入Service列表页面,当前只有一个Version服务。http://localhost:8085/axis2/services/Version?wsdl
4、下载 axis2-eclipse-codegen-plugin-1.5.4.zip,axis2-eclipse-service-plugin-1.5.4.zip  解压后将plugins 复制到 %ECLIPSE_HOME%\plugins。
http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.5.4/axis2-eclipse-codegen-plugin-1.5.4.zip
http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.5.4/axis2-eclipse-service-plugin-1.5.4.zip

安装完插件后,IDE中选择new->other会看到下面界面

如果安装Axis2插件之后,在eclipse中没有出现界面,就换一个eclipse版本
在版本比较新的eclipse中,安装Axis插件,是把jar复制到%ECLIPSE_HOME%\dropins目录下,而不是plugins目录

AXIS2发布Web Services
一、工程文件

1、新建 Axis2Service1 java工程。
2、新建 \Axis2Service1\src\ws\TestWs.java

package ws;
public class TestWs {
public String showName(String name) {return name; }
public String getName() {return "Axis2Service Sample"; }
}

二、arr部署方式
1、手动打包
新建\Axis2Service1\deploy文件夹 ,将\Axis2Service1\bin下的class文件复制过来。
新建\Axis2Service1\deploy\META-INF\services.xml文件

<service name="AxisService">
<description>AxisService</description>
<parameter name="ServiceClass">ws.TestWs</parameter>
<operation name="showName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<operation name="getName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</operation>
</service>

生成aar包 \Axis2Service1\deploy>jar cvf AxisService.aar . (注意带.号)

2、插件打包
IDE中选择New->other->Axis2 Service Archiver,点击Next;
Class File Location:选择Axis2Service1\bin目录,点击Next;
勾选Skip WSDL,点击Next;
Service Archiver 选择jar位置,如果没有jar包就直接点击Next;
勾选Generate the service xml automatically 自动生成XML file文件,点击Next
service name,输入:AxisService,然后在class name 中填写要发布的类(全路径),点击load。勾选 Search declared methods only。点击next

output File location,输入:D:\ ; output File Name,输入artiver文件的名称 AxisService。点击finish。
提示 Service Archvie generated successfully! 注册表明,生成成功。
3、发布AxisService
AxisService.aar复制到%TOMCAT-HOME%/webapps/axis2/WEB-INF/services下。(不打aar包,\Axis2Service1\deploy下面复制过去也是可以)

打开http://localhost:8085/axis2/services/listServices 看到

三、独立部署

1、新建java web project工程。
2、文件复制
%TOMCAT-HOME%\webapps\axis2\WEB-INF\lib 复制到 \Axis2Service2\WebRoot\WEB-INF\lib 下,并加入工程引用。
%TOMCAT-HOME%\webapps\axis2\WEB-INF\conf 复制到 \Axis2Service2\WebRoot\WEB-INF\conf
%TOMCAT-HOME%\webapps\axis2\WEB-INF\modules 复制到 \Axis2Service2\WebRoot\WEB-INF\modules
3、web.xml 代码如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="wmf" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>

2、新建 \Axis2Service2\src\ws\TestWs.java

package ws;
public class TestWs {
public String showName(String name) {return name; }
public String getName() {return "Axis2Service Sample"; }
}

3、新建\Axis2Service2\WebRoot\WEB-INF\services目录。
4、新建一个AxisService服务
AxisService\META-INF\services.xml

<service name="AxisService">
<description>AxisService</description>
<parameter name="ServiceClass">ws.TestWs</parameter>
<operation name="showName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<operation name="getName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</operation>
</service>

启动tomcat后,访问http://localhost:8085/Axis2Service2/services/AxisService?wsdl看是否正常。

AXIS2调用Web Services

一、客户端stub文件生成
1、脚本生成方式
去AXIS2的解压目录下bin(%AXIS2_HOME%\bin\)下执行下面语句
wsdl2java -uri http://localhost:8085/Axis2Service2/services/AxisService?wsdl -p ws -s -o stub
-p参数指定了生成的Java类的包名
-o参数指定了生成的一系列文件保存的根目录
在stub\src\ws自动生成AxisServiceStub.java

2、插件生成方式
IDE中选择New->other->Axis2 Code Generator,点击Next;
勾选Generate Java source code from a WSDL file,点击Next;
WSDL file location,输入:http://localhost:8085/Axis2Service2/services/AxisService?wsdl,点击Next;
如果路径不对会提示:Specified WSDL is invalid!, Please select a validated *.wsdl/*.xml file on previous page.
正确的话界面如下,点击next;

指定输入路径,点击Next

提示:All operations completed successfully! 生成成功。在D:\src\ws 自动生成了stub一系列文件,其中ws是包名。

上面2种方式生成的stub类有点不一样,脚本生成方式是单一文件,插件生成方式生成的一系列文件。

二、客户端调用
脚本生成方式为例子,插件生成的类似。

1、新建 java工程 Axis2Client
新建\Axis2Client\lib文件夹
将%AXIS2_HOME%\lib\ 下的jar包复制到\Axis2Client\lib,并加入工程引用中
将通过脚本生成的单一AxisServiceStub.java文件 加入到src\ws下
2、新建test.TestWs.java 主要代码如下

//初始化Sub类
AxisServiceStub stub = new AxisServiceStub();
//传递AxisServiceStub.ShowName对象,相关参数在这边赋值。
AxisServiceStub.ShowName command = new AxisServiceStub.ShowName();
command.setName("Hello!");
//取得返回值
String name = stub.showName(command).get_return();
System.out.println(name);

调用成功后控制台输出:Hello!

上面代码展示了如何从webservice中 调用方法。

最新文章

  1. python venv下安装mysql出错 解决方法
  2. iOS开发——源代码管理——git(分布式版本控制和集中式版本控制对比,git和SVN对比,git常用指令,搭建GitHub远程仓库,搭建oschina远程仓库 )
  3. bootstrap API地址
  4. BZOJ 1031 字符加密
  5. oracle中的exists 和not exists 用法详解(转)
  6. 激活windows server 2012 R2的方法
  7. https原理及实践
  8. Codeforces round 1086
  9. 关于js中close()方法的兼容性问题
  10. SQL server常用函数使用示例
  11. FTP:mget匹配文件名后下载
  12. Django+Vue.js框架快速搭建web项目
  13. 004-mac上安装以及Nginx 配置文件nginx.conf详解
  14. CCF 2015-03-4 网络延时
  15. 分享6款优秀的 AR/VR 开源库
  16. 使用Idea搭建Spring Boot环境
  17. Leecode刷题之旅-C语言/python-202快乐数
  18. mysql root设置密码 linux
  19. Unity3D delegate 用法
  20. tomcat8.5配置优化

热门文章

  1. eos开发指南
  2. 贵州省未来二十年的投资机会的探讨1&gt;
  3. RDL/RDLC批量单据打印 [转]
  4. 一个改变this指向bind的函数,vue源代码
  5. JavaScript初探系列之数组的基本操作
  6. DAY3敏捷冲刺
  7. Windows平台下安装.net coreclr
  8. LintCode-50.数组剔除元素后的乘积
  9. Windows SDK 非模态对话框的消息处理
  10. Linux 路由 学习笔记 之一 相关的数据结构