Apache axis2 + Eclipse 开发 WebService
yd小结
注意:
1.axis2的2个插件的版本必须与引入的jar包匹配,如果不同则可能报以下错误
“没有实现序列化方法”或
“
org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter cannot be resolved to a type
”,
“org.apache.axis2.AxisFault: wrong number of arguments”
2.如果eclipse已经安装了axis2相关的2个插件,要看下是什么版本的。
方法是:help>install new software->what's alreday installed?->plug-ins里面,找到“Axis2 codegen winzard plug-in”和“Axis2 Server Maker”查看其version
一、简介
Apache Axis2是下一代 Apache Axis。Axis2 虽然由 Axis 1.x 处理程序模型提供支持,但它具有更强的灵活性并可扩展到新的体系结构。Axis2 基于新的体系结构进行了全新编写,而且没有采用 Axis 1.x 的常用代码。支持开发 Axis2 的动力是探寻模块化更强、灵活性更高和更有效的体系结构,这种体系结构可以很容易地插入到其他相关 Web 服务标准和协议(如 WS-Security、WS-ReliableMessaging 等)的实现中。Apache Axis2 是Axis的后续版本,是新一代的SOAP引擎。 官方网站:http://axis.apache.org/axis2/java/core/index.html
二、下载
Apache Axis2 下载页面:http://axis.apache.org/axis2/java/core/download.cgi (当前最新版本1.6.2)
Apache Axis2 Binary Distribution(1.6.2):http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip
WAR Distribution:http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-war.zip
Eclipse 插件:
Service Archive Wizard - Eclipse Plug-in(用来将服务代码打包成后缀名为.aar文件的插件):
Code Generator Wizard - Eclipse Plug-in(用来将服务代码生成wsdl文件以及解析将wsdl文件生成客户端代码的插件):
安装插件:
我用的是MyEclipse10,以我的环境为例:将两个插件解压后放到D:\sdk\MyEclipse\MyEclipse 10\dropins目录下面,启动MyEclipse
File - New - Other 可以找到:
三、部署axis2 war
解压下载的axis2-1.6.2-war.zip 得到一个axis2.war文件,将这个文件丢到tomcat\webapps目录,启动tomcat 访问http://localhost:8080/axis2
看到如下界面,部署成功。
四、编写服务代码
- package com.xcy;
- /**
- * @author 肖纯勇(Siuon)
- * @version 1.0
- * @create 2012-7-19 下午8:23:49
- */
- public class Axis2WB {
- /**
- * 提供了一个说Hello的服务
- * @return
- */
- public String sayHello(String name){
- return "Hello "+name;
- }
- /**
- * 提供了一个做加法的服务
- * @param a
- * @param b
- * @return
- */
- public int add(int a,int b){
- return a + b;
- }
- }
五、将服务代码打包成arr文件:
Eclipse菜单- New - File - Other -Axis2 Service Archiver
class file location:为刚刚写的Axis2WB类所在工程的bin目录
选择skip wsdl
如果你的Axis2WB有引用jar包,则在这里选择。我写的没有,所以next
由于我们没有编写service.xml,所以勾选让它自动生成,next
输入服务名称(随意)、类全名、load、next
设置aar文件名以及存放目录(我是放在桌面)--Finish:
完成后,可以看到桌面上多了一个axis2wb.aar文件,我们用winrar打开:
有没有感觉很眼熟?很像一个jar包、我们点击META-INF目录进去,可以看到插件给我们生成的一个service.xml,打开看看(是不是明白插件做了些啥了):
六、发布
将axis2wb.aar文件丢到之前部署的axis2应用的WEB-INF\services\目录下面,重启tomcat
再访问http://localhost:8080/axis2/ 点击Service
看到上图,说明发布成功
七、生成客户端代码
你可以用jdk6自带的wsimport工具生成客户端代码:Java 6 开发 WebService
也可以通过axis2 的Eclipse插件生成客户端代码:
Eclipse菜单-File-New-Other-Axis2 Code Generator
Generate Java source code from a WSDL file:根据WSDL生成webservice客户端的java代码。(在这里,我们选择这个)
Generate a WSDL from a Java source file :根据一个java源文件生成wsdl文件(这个源文件是打算发布成Web服务的java源文件,例如本demo中的Axis2WB.java)。
生成完代码后,你会发现报错,原因是因为缺少相关的jar包。
解压在第一步中下载的axis2 binary.zip 将解压后的目录中的lib下面的所有jar包,拷进来,添加到class path中:
8、调用Web服务
- package test;
- import java.rmi.RemoteException;
- import com.xcy.Add;
- import com.xcy.AddResponse;
- import com.xcy.Axis2WB;
- import com.xcy.Axis2WBStub;
- import com.xcy.SayHello;
- import com.xcy.SayHelloResponse;
- /**
- * @author 肖纯勇(Siuon)
- * @version 1.0
- * @create 2012-7-19 下午9:18:23
- */
- public class Test {
- public static void main(String[] args) throws RemoteException {
- //创建客户端对象
- Axis2WB axis2wb = new Axis2WBStub();
- //new一个调用sayHello方法需要的参数SayHello,并且设置name
- SayHello sayHello = new SayHello();
- sayHello.setName("Siuon");
- //调用web服务
- SayHelloResponse sayHelloResponse = axis2wb.sayHello(sayHello);
- //拿到返回结果
- System.out.println(sayHelloResponse.get_return());
- Add add = new Add();
- add.setA(5);
- add.setB(3);
- AddResponse addResponse = axis2wb.add(add);
- System.out.println(addResponse.get_return());
- }
- }
结果:
(The End)
Apache axis2 + Eclipse 开发 WebService的更多相关文章
- Eclipse + Apache Axis2 发布RESTful WebService(三)第一个程序Hello Axis2 !(未成功)
此路不通 Axis2发布SOAP WebService非常简单,建一个Dynamic Web Project,然后为它建一个Axis的Web Service(Tomcat7+JDK),就会生成Clas ...
- Eclipse + Apache Axis2 发布RESTful WebService(二)配置开发环境
1. 下载axis2相关软件地址:http://axis.apache.org/axis2/java/core/download.html 2. 安装插件:将axis2-eclipse-codegen ...
- Eclipse + Apache Axis2 发布RESTful WebService(一)基础知识
1.什么是WebService 学习 WebService 第一步:体系结构.三元素SOAP/WSDL/UDDI 2.什么是Axis2 Axis2是Apache一套崭新的WebService引擎(框架 ...
- Eclipse + Apache Axis2 发布SOAP WebService(三)第一个程序Hello Axis2 SOAP!
因为Axis2同时支持SOAP和RESTful的WebService开发. 我的目标主要是RESTful,这里简单记录一个SOAP的小例子: 原文地址:https://jingyan.baidu.co ...
- Myeclipse+Axis2+Tomcat开发webService
1. 下载文件: 需要在axis2官网下载两种类型的axis2文件,bin版和war版(下载地址:http://axis.apache.org/axis2/java/core/download.cg ...
- 使用eclipse开发webService很简单
原文转自:http://blog.csdn.net/guo_rui22/article/details/6253745 使用Eclipse生成一个WebService应用 1.创建一个Dynamic ...
- 用 Eclipse 开发 WebService 项目
1.安装tomcat 2.安装CXF 一.为新渠道webservice加入到项目中 首先,创建一个springboot项目,名为webservice-baffle(附件中). 第二步,新建web se ...
- Java开发Webservice的组件
参考:http://bbs.csdn.net/topics/390900831 转自:http://blog.csdn.net/dragoo1/article/details/50759222 htt ...
- Java开发WebService的几种方法--转载
webservice的应用已经越来越广泛了,下面介绍几种在Java体系中开发webservice的方式,相当于做个记录. 1.Axis2 Axis是apache下一个开源的webservice开发组件 ...
随机推荐
- vc 中调用COM组件的方法
需求:1.创建myCom.dll,该COM只有一个组件,两个接口: IGetRes--方法Hello(), IGetResEx--方法HelloEx() 2.在工程中导入组件或类型库 #im ...
- SQL 中 SELECT 语句的执行顺序
好像自已在书写 SQL 语句时由于不清楚各个关键字的执行顺序, 往往组织的 SQL 语句缺少很好的逻辑, 凭感觉 "拼凑" ( 不好意思, 如果您的 SQL 语句也经常 " ...
- ORACLE object_id和data_object_id
object_id和data_object_id 都是对象的唯一标识. object_id是对象的逻辑标识 data_object_id是对象的物理标识 对于没有物理存储的对象,data_object ...
- Java学习笔记14--动态代理
InvocationHandler接口 public interface InvocationHandler{ public Object invoke(Object proxy,Method met ...
- hdu 5748(LIS) Bellovin
hdu 5748 Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an. 定义F(a1,a2,...,an)=(f1,f2,...,fn ...
- ABP的Zero Sample
下载自:https://github.com/aspnetboilerplate/module-zero 打开D:\ABP\module-zero-master\sample里的ModuleZeroS ...
- 2016 小马哥 IOS
2016 小马哥 IOS 最新视频完整版 链接:http://pan.baidu.com/s/1c1EQlBM 密码:mxkt
- GATK使用说明-GRCh38(Genome Reference Consortium)(二)
Reference Genome Components 1. GRCh38 is special because it has alternate contigs that represent pop ...
- Splunk及splunkforward简单部署配置
部署环境 操作系统 服务器操作系统版本:CentOS release 6.5 (Final) 2.6.32-431.el6.x86_64 软件 软件版本:splunk-6.4.0 tar: splun ...
- javascript中闭包的概念
这个是每个前端工程师绕不开的一个问题,网上各种资料很多,整个春节,我仔细研读了红皮经典中关于这一块的注释,加深了对这一块的理解. 有好几个概念需要重申一下.以下都是我的理解: 1. 闭包是javasc ...