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开发组件 ...
随机推荐
- Django web 基础
一.Django概述 Django大而全; 创建Django工程:django-admin startproject sitename 创建django之后生成的目录结构如下: Project Pro ...
- SVM1 线性SVM
一.Linear Support Vector Machine 接下来的讨论假设数据都是线性可分的. 1.1 SVM的引入:增大对测量误差的容忍度 假设有训练数据和分类曲线如下图所示: 很明显,三个分 ...
- 在eclipse中运行perl代码,需要配置的插件以及方法
Eclipse配置正则表达式 网址:http://www.cnblogs.com/itech/archive/2010/02/23/1671676.html perl的环境配置以及在Eclipse中安 ...
- 使用rownum对oracle分页
以Student表为例进行分页 建表及插入 -- 有表结构如下 create table STUDENT ( sno INTEGER, sname ), sage INTEGER ); -- 插入数据 ...
- A 浪哥的烦恼 完全背包dp
https://biancheng.love/contest-ng/index.html#/131/problems 首先,去到n点的最小时间是所有数加起来. 然后,如果我1 --- 2,然后再2-- ...
- background-orgin属性
重点内容是:背景的显示范围是在元素的内边距之内的,如果要想改变显示范围,可以使用background-orgin和background-clip进行调整. (1)background-orgin有三个 ...
- UIImageView、UISlider、UISwitch、UIStepper、UISegmentControl
UIImageView——图像视图 作用:专门用来显示图片的控件 . 设置图像 [self.imageView setImage:[UIImage imageNamed:@"abc.png& ...
- as 和 is 区别
as 将对象转换某类型,如果失败则返回null.is用来判断对象是否为某个类型,在判断过程中会对对象进行两次转换,而as只有一次转换,故as效率高.
- iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题
使用AFNetworking出现报错: error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "R ...
- linux eclipse epic perl padwalker
1, 在Eclipse中安装EPIC:Help->Install New Software->Add:name:EPICLocation:http://e-p-i-c.sourceforg ...