1.下载①axis2-1.7.4-bin.zip、②axis2-1.7.4-war.zip、③axis2-eclipse-service-plugin-1.7.4.zip、④axis2-eclipse-codegen-plugin-1.7.4.zip(下载地址:http://axis.apache.org/axis2/java/core/download.cgi);

2.将②axis2-1.7.4-war.zip解压后得到的axis2.war文件放到Tomcat下的webapps目录下,重启Tomcat访问http://localhost:8080/axis2/可看到内容;

3.将③axis2-eclipse-service-plugin-1.7.4.zip、④axis2-eclipse-codegen-plugin-1.7.4.zip解压后得到的插件放到Myeclipse的dropins目录下,重启Myeclipse生效;

4.新建web project,名为Axis2Service,新建student类:

package cn.lxc.bean;

import java.io.Serializable;

public class Student implements Serializable{
private static final long serialVersionUID = 4634408543522196927L; private int id;
private int number;
private String name;
private String tel;
private String address; public Student() { }
public Student(int id, int number, String name, String tel, String address) {
this.id = id;
this.number = number;
this.name = name;
this.tel = tel;
this.address = address;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}

创建MyService类,用于发布webservice服务:

package cn.lxc.service;

import java.util.Arrays;

import cn.lxc.bean.Student;

public class MyService {

    public String getGreeting(String name){
return "您好,"+name+"!";
} public String addStudent(Student stu){
if(null != stu)
return "您好,"+stu.getName()+"!";
else
return "student is null!";
} public Student queryStudent(){
Student stu = new Student(111111, 20170302, "刘新成", "18810464513", "北京");
return stu;
} public String addStudents(Student[] students){
if(null != students)
return Arrays.toString(students);
else
return "students is null";
} public Student[] queryStudents(){
Student[] stuArr = new Student[2];
Student st1 = new Student(222222, 20170301, "刘德华", "13893260374", "香港");
Student st2 = new Student(111111, 20170302, "刘新成", "18810464513", "北京");
stuArr[0] = st1;
stuArr[1] = st2;
return stuArr;
}
}

5.发布webservice:

(1)右击项目名,Axis2Service——>New——>Other——>Axis2 Service Archiver

(2)Class File Location路径:项目WEB-INF下的classes目录(例如:E:\Workspaces\Axis2Service\web\WEB-INF\classes);

(3)勾选Skip WSDL,点击下一步;

(4)Add any external libraries忽略,下一步;

(5)勾选Generator the service xml automatically,下一步;

(6)Service name:填写要发布的service名称,Class name:要发布的类的全称(例如:cn.lxc.service.MyService),下一步;

(7)Output file location:指定要发布的service到tomcat的axis2项目容器中(例如:C:\apache-tomcat-7.0.69\webapps\axis2\WEB-INF\services);点击finish即可;

(8)启动tomcat,访问http://localhost:8080/axis2/services/listServices,即可看到新发布的service:MyService,点击MyService链接,得到wsdl文件。

6.使用客户端调用webservice:

(1)新建web project,命名为Axis2Client,将①axis2-1.7.4-bin.zip解压后的包下的lib目录下的jar包添加到项目web/WEB-INF/lib目录下;

(2)使用myeclipse的axis2插件Axis2 Code Generator生成客户端;

(3)右击项目Axis2Service,New——>Other——>Axis2 Code Generator,点击下一步;

(4)选择Generator Java source code from a WSDL file,点击下一步;

(5)WSDL file location:路径指向点击MyService链接得到的wsdl文件(例如:C:\Users\liuxincheng\Desktop\MyService.xml),点击下一步;

(6)Codegen option:默认default,选择custom(定制),其他默认,点击下一步;

(7)选择Browse and select a project on current eclipse workspaceOutput Path:选择Axis2Client的路径,例如(E:\Workspaces\Axis2Client),点击finish即可;

(8)创建Test类测试:

package cn.lxc.test;

import cn.lxc.bean.xsd.Student;
import cn.lxc.service.AddStudent;
import cn.lxc.service.AddStudentResponse;
import cn.lxc.service.AddStudents;
import cn.lxc.service.AddStudentsResponse;
import cn.lxc.service.GetGreeting;
import cn.lxc.service.GetGreetingResponse;
import cn.lxc.service.MyServiceStub;
import cn.lxc.service.QueryStudent;
import cn.lxc.service.QueryStudentResponse;
import cn.lxc.service.QueryStudents;
import cn.lxc.service.QueryStudentsResponse; public class Test {
public static void main(String[] args){
// 设置远程服务调用地址
String target = "http://127.0.0.1:8080/axis2/services/MyService";
try{
// 根据地址构造用户存根
MyServiceStub stub = new MyServiceStub(target);
// 1. 调用getGreeting方法,设置入参对象及属性,入参,回参为基本类型String
GetGreeting getGreeting = new GetGreeting();
getGreeting.setName("Axis");//设置方法参数
GetGreetingResponse ggr = stub.getGreeting(getGreeting);
// 接收方法返回值
String getResult = ggr.get_return();
System.out.println(getResult);
// 2. 调用AddStudent方法,设置入参对象及属性,入参为bean
AddStudent addStudent = new AddStudent();
Student student = new Student();
student.setAddress("shanghai");
student.setId(123456);
student.setName("张三");
student.setNumber(12321312);
student.setTel("13678956529");
addStudent.setStu(student);
AddStudentResponse asr = stub.addStudent(addStudent);
// 接收方法返回值
String addResult = asr.get_return();
System.out.println(addResult);
// 3. 调用queryStudent方法,设置入参对象及属性,回参为bean
QueryStudent queryStudent = new QueryStudent();
QueryStudentResponse qsr = stub.queryStudent(queryStudent);
// 接收方法返回值
Student qsResult = qsr.get_return();
System.out.println("地址:" + qsResult.getAddress() + ", ID:"
+ qsResult.getId() + ", 姓名:" + qsResult.getName() + ", 号码:"
+ qsResult.getNumber() + ", 电话:" + qsResult.getTel());
System.out.println("<------------------------------------------------------>");
// 4. 调用queryStudents方法,设置入参对象及属性,返回bean数组
QueryStudents queryStudents = new QueryStudents();
QueryStudentsResponse qssr = stub.queryStudents(queryStudents);
// 接收方法返回值
Student[] qssResult = qssr.get_return();
for (int i = 0; i < qssResult.length; i++){
System.out.println("地址:" + qssResult[i].getAddress() + ", ID:"
+ qssResult[i].getId() + ", 姓名:"
+ qssResult[i].getName() + ", 号码:"
+ qssResult[i].getNumber() + ", 电话:"
+ qssResult[i].getTel());
}
// 5. 调用AddStudents方法,设置入参对象及属性,入参为bean数组
AddStudents addStudents = new AddStudents();
Student st = new Student();
st.setAddress("shanghai");
st.setId(123456);
st.setName("servyou");
st.setNumber(12321312);
st.setTel("13678956529");
Student st2 = new Student();
st2.setAddress("shanghai");
st2.setId(123456);
st2.setName("servyou");
st2.setNumber(12321312);
st2.setTel("13678956529");
addStudents.addStudents(st);
addStudents.addStudents(st2);
AddStudentsResponse assr = stub.addStudents(addStudents);
// 接收方法返回值
String addstsResult = assr.get_return();
System.out.println(addstsResult);
} catch (Exception e){
e.printStackTrace();
}
}
}

Axis2开发实例的更多相关文章

  1. axis2开发实例(二)建立独自的新工程

    第一部分 环境搭建 1.  环境搭建 (1)    下载Axis2服务包:axis2-1.6.2-bin.zip,axis2-1.6.2-war.zip,分别解压到D:\webservice_axis ...

  2. axis2开发实例(一)

    主要参考<axis2之webservice新手超详细教程http://wenku.baidu.com/view/6eae036d011ca300a6c390a4.html> <axi ...

  3. ecshop二次开发 给商品添加自定义字段【包含我自己进一步的开发实例详解】

    本文包含商品自定义添加教程及进一步的开发实例: 教程: 说起自定义字段,我想很多的朋友像我一样会想起一些开源的CMS(比如Dedecms.Phpcms.帝国)等,他们是可以在后台直接添加自定义字段的. ...

  4. RDIFramework.NET -.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(WebForm版)

    RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(WebForm版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之 ...

  5. RDIFramework.NET-.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(MVC版)

    RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(MVC版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之产品管理 ...

  6. Cocos2d-x 3.X手游开发实例详解

    Cocos2d-x 3.X手游开发实例详解(最新最简Cocos2d-x手机游戏开发学习方法,以热门游戏2048.卡牌为例,完整再现手游的开发过程,实例丰富,代码完备,Cocos2d-x作者之一林顺和泰 ...

  7. 免费的HTML5连载来了《HTML5网页开发实例详解》连载(二)

    最近新浪.百度.腾讯.京东.大众点评.淘宝等流行的网站都加大了招聘HTML5的力度,HTML5开发人员成了抢手货,本次连载的是由大众点评前端工程师和一淘网前端工程师基情奉献的<HTML5网页开发 ...

  8. RDIFramework.NET开发实例━表约束条件权限的使用-Web

    RDIFramework.NET开发实例━表约束条件权限的使用-Web 在上一篇文章“RDIFramework.NET开发实例━表约束条件权限的使用-WinForm”我们讲解了在WinForm下表约束 ...

  9. RDIFramework.NET开发实例━表约束条件权限的使用-WinForm

    RDIFramework.NET开发实例━表约束条件权限的使用-WinForm 在实际的应用中,客户常有这样的需求,指定用户或角色可以看指定条件下的数据,这里的“指定条件”在RDIFramework. ...

随机推荐

  1. java Spring 事务的初次使用与验证

    事务,只要是为了保证数据的原子性.避免出现脏数据. 下面来讲解下spring是如何使用事务的. 1.配置事务.这里采用的是注解的模式 <!-- 配置事务管理器 ,如果你暂时未使用到事务可以不配置 ...

  2. 【WPF】ListBox无法滚动

    问题:ListBox显示多个条目时,无法滚动,也不显示滚动条. 办法: 给ListBox控件加上ScrollViewer.VerticalScrollBarVisibility和ScrollViewe ...

  3. springMVC demo搭建

    1.使用idea新建一个基于maven的web项目,参考 http://www.cnblogs.com/winkey4986/p/5279820.html 2.采取了比较偷懒的配置方法,只配置了一个D ...

  4. ExtJs TreePanel 全选与反选

    selectAll: function() { this.getRootNode().eachChild(function (child) { child.set('checked', true); ...

  5. 数据库——SQL中EXISTS怎么用3(转)

    有一个查询如下: 1 SELECT c.CustomerId, CompanyName   2 FROM Customers c   3 WHERE EXISTS(   4     SELECT Or ...

  6. 一站式学习Wireshark(七):Statistics统计工具功能详解与应用

    Wireshark一个强大的功能在于它的统计工具.使用Wireshark的时候,我们有各种类型的工具可供选择,从简单的如显示终端节点和会话到复杂的如Flow和IO图表.本文将介绍基本网络统计工具.包括 ...

  7. Linux服务器同步时间

    进行Linux服务器的时间同步是一件需要注意的事情,不然,集群中的服务器时间不同将导致许多奇怪问题发生, 如果没有安装crontab,那么,使用yum install crontabs进行安装和启动, ...

  8. 运行带distance field的Hiero

    从http://libgdx.badlogicgames.com/releases/下载zip包并解压,切换到解压后的目录,执行: java -cp gdx.jar;gdx-natives.jar;g ...

  9. 让IE6支持min-height,max-height等的方法

    1.IE6支持max-height解决方法    IE6支持最大高度解决CSS代码:.yangshi{max-height:1000px;_height:expression((document.do ...

  10. 16 款最流行的JavaScript 框架

    1. jQuery – Javascript框架 jQuery 是最流行的 JavaScript 框架,它简化了HTML 文档遍历.事件处理.动画和Ajax交互.jQuery插件非常之多. 2. Do ...