首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

axis2 容易入手

2012-10-31 
axis2 简单入手准备工作: 1.下载了axis2-eclipse-service-archiver-wizard.zip axis2-eclipse-codegen-wiz

axis2 简单入手

准备工作:

1.下载了axis2-eclipse-service-archiver-wizard.zip

axis2-eclipse-codegen-wizard.zip

两个eclipse插件,貌似要1.3版本的才能支持在用java类生成wsdl时选择skip wsdl

?

2.下载axis2-1.4.1和axis2-1.4.1-war

?

一.简单入门

1.编写服务端代码

?

2.用axis2-eclipse-service-archiver 生成,new - other,选择axis2 service archiver ,然后进入向导,注意第二步“add the wsdl file”的时候选择“skip wsdl”,最后生成aar。生成的aar已经包含了services.xml。

services.xml内容如下:

?

?

?

3.先把下载的axis2.war放到[tomcat_home]\webapps下。启动tomcat解压axis2.war。

然后把刚才生成的aar放在[tomcat_home]\webapps\axis2\WEB-INF\services下,重新启动tomcat

就可以在http://localhost:8888/axis2/services/MyService?wsdl 访问。

?

4.生成客户端访问。用axis2-eclipse-codegen生成客户端代码。

-------------------------------------------------

如果用插件生成时,有如下错误,java.lang.reflect.InvocationTargetException

?

,解决办法如下

Axis2_Codegen_Wizard_1.3.0从wsdl生产java客户端代码(首先要保证webservice已经启动)时候出现invocationTargetException,解决办法如下:

?

1). Download the following jar files:
stax-api-1.0.1.jar
backport-util-concurrent-3.1.jar
and save them to eclipse/plugins/[Axis2 Codegen Wizard]/lib (replace [Axis2 Codegen Wizard] with the real plugin directory).
2). Add to the eclipse/plugins/[Axis2 Codegen Wizard]/plugin.xml the followings (to the <runtime> element), if they are missing:
<library name="lib/stax-api-1.0.1.jar">
<export name="*"/>
</library>

<library name="lib/backport-util-concurrent-3.1.jar">
<export name="*"/>
</library>

?

或者还是直接用命令吧:

在cmd下运行:
[your_axis2_home]\bin> wsdl2java.bat -uri http://localhost:8888/axis2/services/MyService?wsdl -o D:\输出目录

-------------------------------------------------------

通过上面办法顺利生成客户端代码之后,可以看到生成了MyServiceCallbackHandler和MyServiceStub

【xxxxxxStub和xxxxxxxCallbackHandler】的package 默认为service类的所在package

QName也为所在package

xxxxxxStub默认wsdl为你生成wsdl2java时使用的wsdl

?

利用生成的MyServiceCallbackHandler和MyServiceStub,编写调用代码如下(编译时要先引入axis2的jar)

?

二.不用aar发布web service的方法。

1.在web.xml中配置AxisServlet。如下所示:

?2.在[yourWebProject]\WebRoot\WEB-INF下新建services目录,在在services目录新建 deployService目录(名字随便,真正的webservice的服务名是services.xml里面定义的),在deployService 下新建META-INF目录,在META-INF下放置你的services.xml。

目录结构如下:

axis2 容易入手

?

3.访问http://localhost:8080/[yourWebProject]/services/MyService?wsdl 即可

?

热点排行