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文件的插件):

http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-service-plugin-1.6.2.zip

Code Generator Wizard - Eclipse Plug-in(用来将服务代码生成wsdl文件以及解析将wsdl文件生成客户端代码的插件):

http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-codegen-plugin-1.6.2.zip

安装插件:

我用的是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

看到如下界面,部署成功。

四、编写服务代码

  1. package com.xcy;
  2. /**
  3. * @author 肖纯勇(Siuon)
  4. * @version 1.0
  5. * @create 2012-7-19 下午8:23:49
  6. */
  7. public class Axis2WB {
  8. /**
  9. * 提供了一个说Hello的服务
  10. * @return
  11. */
  12. public String sayHello(String name){
  13. return "Hello "+name;
  14. }
  15. /**
  16. * 提供了一个做加法的服务
  17. * @param a
  18. * @param b
  19. * @return
  20. */
  21. public int add(int a,int b){
  22. return a + b;
  23. }
  24. }

五、将服务代码打包成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服务

    1. package test;
    2. import java.rmi.RemoteException;
    3. import com.xcy.Add;
    4. import com.xcy.AddResponse;
    5. import com.xcy.Axis2WB;
    6. import com.xcy.Axis2WBStub;
    7. import com.xcy.SayHello;
    8. import com.xcy.SayHelloResponse;
    9. /**
    10. * @author 肖纯勇(Siuon)
    11. * @version 1.0
    12. * @create 2012-7-19 下午9:18:23
    13. */
    14. public class Test {
    15. public static void main(String[] args) throws RemoteException {
    16. //创建客户端对象
    17. Axis2WB axis2wb = new Axis2WBStub();
    18. //new一个调用sayHello方法需要的参数SayHello,并且设置name
    19. SayHello sayHello = new SayHello();
    20. sayHello.setName("Siuon");
    21. //调用web服务
    22. SayHelloResponse sayHelloResponse = axis2wb.sayHello(sayHello);
    23. //拿到返回结果
    24. System.out.println(sayHelloResponse.get_return());
    25. Add add = new Add();
    26. add.setA(5);
    27. add.setB(3);
    28. AddResponse addResponse = axis2wb.add(add);
    29. System.out.println(addResponse.get_return());
    30. }
    31. }

结果:

(The End)

Apache axis2 + Eclipse 开发 WebService的更多相关文章

  1. Eclipse + Apache Axis2 发布RESTful WebService(三)第一个程序Hello Axis2 !(未成功)

    此路不通 Axis2发布SOAP WebService非常简单,建一个Dynamic Web Project,然后为它建一个Axis的Web Service(Tomcat7+JDK),就会生成Clas ...

  2. Eclipse + Apache Axis2 发布RESTful WebService(二)配置开发环境

    1. 下载axis2相关软件地址:http://axis.apache.org/axis2/java/core/download.html 2. 安装插件:将axis2-eclipse-codegen ...

  3. Eclipse + Apache Axis2 发布RESTful WebService(一)基础知识

    1.什么是WebService 学习 WebService 第一步:体系结构.三元素SOAP/WSDL/UDDI 2.什么是Axis2 Axis2是Apache一套崭新的WebService引擎(框架 ...

  4. Eclipse + Apache Axis2 发布SOAP WebService(三)第一个程序Hello Axis2 SOAP!

    因为Axis2同时支持SOAP和RESTful的WebService开发. 我的目标主要是RESTful,这里简单记录一个SOAP的小例子: 原文地址:https://jingyan.baidu.co ...

  5. Myeclipse+Axis2+Tomcat开发webService

    1.  下载文件: 需要在axis2官网下载两种类型的axis2文件,bin版和war版(下载地址:http://axis.apache.org/axis2/java/core/download.cg ...

  6. 使用eclipse开发webService很简单

    原文转自:http://blog.csdn.net/guo_rui22/article/details/6253745 使用Eclipse生成一个WebService应用 1.创建一个Dynamic ...

  7. 用 Eclipse 开发 WebService 项目

    1.安装tomcat 2.安装CXF 一.为新渠道webservice加入到项目中 首先,创建一个springboot项目,名为webservice-baffle(附件中). 第二步,新建web se ...

  8. Java开发Webservice的组件

    参考:http://bbs.csdn.net/topics/390900831 转自:http://blog.csdn.net/dragoo1/article/details/50759222 htt ...

  9. Java开发WebService的几种方法--转载

    webservice的应用已经越来越广泛了,下面介绍几种在Java体系中开发webservice的方式,相当于做个记录. 1.Axis2 Axis是apache下一个开源的webservice开发组件 ...

随机推荐

  1. vc 中调用COM组件的方法

    需求:1.创建myCom.dll,该COM只有一个组件,两个接口:   IGetRes--方法Hello(),   IGetResEx--方法HelloEx() 2.在工程中导入组件或类型库  #im ...

  2. SQL 中 SELECT 语句的执行顺序

    好像自已在书写 SQL 语句时由于不清楚各个关键字的执行顺序, 往往组织的 SQL 语句缺少很好的逻辑, 凭感觉 "拼凑" ( 不好意思, 如果您的 SQL 语句也经常 " ...

  3. ORACLE object_id和data_object_id

    object_id和data_object_id 都是对象的唯一标识. object_id是对象的逻辑标识 data_object_id是对象的物理标识 对于没有物理存储的对象,data_object ...

  4. Java学习笔记14--动态代理

    InvocationHandler接口 public interface InvocationHandler{ public Object invoke(Object proxy,Method met ...

  5. hdu 5748(LIS) Bellovin

    hdu 5748 Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na​1​​,a​2​​,...,a​n​​. 定义F(a1,a2,...,an)=(f1,f2,...,fn ...

  6. ABP的Zero Sample

    下载自:https://github.com/aspnetboilerplate/module-zero 打开D:\ABP\module-zero-master\sample里的ModuleZeroS ...

  7. 2016 小马哥 IOS

    2016  小马哥 IOS 最新视频完整版       链接:http://pan.baidu.com/s/1c1EQlBM 密码:mxkt

  8. GATK使用说明-GRCh38(Genome Reference Consortium)(二)

    Reference Genome Components 1. GRCh38 is special because it has alternate contigs that represent pop ...

  9. Splunk及splunkforward简单部署配置

    部署环境 操作系统 服务器操作系统版本:CentOS release 6.5 (Final) 2.6.32-431.el6.x86_64 软件 软件版本:splunk-6.4.0 tar: splun ...

  10. javascript中闭包的概念

    这个是每个前端工程师绕不开的一个问题,网上各种资料很多,整个春节,我仔细研读了红皮经典中关于这一块的注释,加深了对这一块的理解. 有好几个概念需要重申一下.以下都是我的理解: 1. 闭包是javasc ...