使用Axis2开发WebService

一、准备

1、下载Axis2、eclipse插件

axis2-1.6.2-war.zip:

http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-war.zip

axis2-1.6.2-bin.zip:

http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip

axis2-eclipse-codegen-plugin-1.6.2.zip:

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

axis2-eclipse-service-plugin-1.6.2.zip:

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

 

2、部署

解压axis2-1.6.2-war.zip将axis2.war部署到tomcat,并访问http://localhost:8080/axis2/

 

3、安装eclipse插件

解压插件,直接将文件拷到plugins目录中。打开eclipse,在package explorer 中点击右键--->选择new---->other

 

 

二、开发服务端

1、建Java Project项目,名称为“myservice”,并创建服务类

 

Java代码 
  1. package com.my.server;    
  2.     
  3. public class SimpleServer {  
  4.     public String simpleMethod(String name) {    
  5.         return name + "说:走别人的路,让别人无路可走。";    
  6.     }  
  7. }  

1、在eclispe 的package Explorer 中点击右键,在菜单中选择新建--->other...----->Axis2 Service Archiver。


 

2、点击next进入类选择页面,在Class File Location选择框中选择类所在的文件夹,即java.class文件所存放位置的根目录。


 

3、点击next进入选择 wsdl文件,选择skip wsdl。


 

4、点击next进入选择jar文件页面。(没有用到外部jar,点击next直接跳过)


 

5、点击next进入选择xml页面。勾选Generate the service xml automatically。


 

6、点击next进入生成xml文件页面。在service name 里填写这个服务所起的名字(simpleServer),在class name中填写要发布的类(全路径),然后点击load 按钮。


 

7、点击next 进入的是输出artiver文件页面,先在output File location 中选择要输出的路径,在output  File Name中输入artiver文件的名称(simpleServer)。


 

 

8、点击finish ,如果看到如下的画面,恭喜你,服务发布成功啦。


 

9、把aar文件放入tomcat中发布。

把生成的aar文件拷贝到tomcat目录中的axis2项目的service目录中位置如图。


 

 

10、启动tomcat,在地址栏中输入http://localhost:8080/axis2 ,你会看到axis2的欢迎画面。


 

 

 

三、开发客户端

将Dynamic web Project项目,名称为client。

1、在eclispe 的package Explorer 中点击右键,在菜单中选择新建--->other...----->Axis2 Code Generator。


 

2、点击next进入,选择从wsdl文件来产生java文件。


 

3、点击next然后选择wsdl文件。


 

4、点击next,进入设置页面,用默认的设置。


 

5.、点击next,选择输出文件的路径。


 

6、点击next,如果看到这个页面,已经生成代码成功。


 

7、引入jar包(\axis2-1.6.2\lib)。


 

8、编写测试方法调用服务。

import com.my.server.SimpleServerStub;

public class SimpleClient {  
   
 public static void main(String[] args) throws Exception{  
    
  //初始化桩文件  
  SimpleServerStub stub = new SimpleServerStub();  
  //初始化SimpleMethod方法。  
  SimpleServerStub.SimpleMethod request = new  SimpleServerStub.SimpleMethod();  
  //调用simpleMethod的setName方法。  
  request.setName("zt");  
  //  
  System.out.println(stub.simpleMethod(request).get_return());
 }  
}  

参考:http://blog.csdn.net/yangsen251024/article/details/7043043

转载于:https://www.cnblogs.com/XueRong-7/p/4503974.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值