axis2 webService开发指南(2)
1 Axis2的简单WebService示例
1.1 新建一个web工程,创建一个类Greeting,用于当作webservice服务
代码如下:
package amyservices; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import Com.WebService.Model.Person; public class Greeting {
public String getGreeting(String name){
return "你好:" + name;
} public int getPrice()
{
return new java.util.Random().nextInt(1000);
} public List<Person> GetPersonList()
{
List<Person> list = new ArrayList<Person>();
Person model = new Person();
model.setKeyID("1214324234234234324");
model.setName("張三");
Calendar birth = Calendar.getInstance();
birth.set(1990, 11, 22);
model.setBirth(birth);
list.add(model);
model = new Person();
model.setKeyID("1214324234234234324");
model.setName("李四");
birth = Calendar.getInstance();
birth.set(1990, 11, 22);
model.setBirth(birth);
System.out.println(birth.toString());
list.add(model);
for(Person item : list)
{
System.out.println(item.getName());
} return list;
} public String PrintNow()
{
Calendar cale = Calendar.getInstance();
Date tasktime=cale.getTime();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(tasktime));
return df.format(tasktime);
}
}
.classpath文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.generic_7.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.jstl_1.2.2">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="WEB-INF/lib"/>
<attribute name="owner.project.facets" value="jst.web.jstl"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>
1.2 点击File-->New-->other,选择Axis2 Service Archiver
配置Class File Location,配置路径到工程的WEB-INF\classess目录下,同时将下图的复选框勾选去掉,继续根据向导完成创建。
创建成功,在axis2的工程目录下,多了我们刚配置好的文件
输入网址http://localhost:8080/axis2/services/listServices,会发现增加了我们刚创建的服务。
2 创建客户端
2.1 创建一个java项目
2.2 新建一个WsClient测试类
代码如下:
package com.amy.client; import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient; public class WsClient {
private RPCServiceClient serviceClient;
private Options options;
private EndpointReference targetERP; public WsClient(String endpoint) throws AxisFault{
this.serviceClient = new RPCServiceClient();
this.options = this.serviceClient.getOptions();
this.targetERP = new EndpointReference(endpoint);
this.options.setTo(this.targetERP);
} public Object[] invokeOp(String targetNamespace, String opName,Object[] opArgs, Class<?>[]opReturnType) throws AxisFault, ClassNotFoundException{
QName opQName = new QName(targetNamespace, opName);
return this.serviceClient.invokeBlocking(opQName, opArgs, opReturnType);
} public static void main(String args[])
{
final String endpointReference = "http://localhost:8080/axis2/services/WebServiceTest1";
final String targetNamesPace = "http://amyservices";
try {
WsClient client = new WsClient(endpointReference);
String opName = "GetPersonList";
Object[] opArgs = new Object[]{};
Class<?>[] opReturnType = new Class[]{Person.class};
Object[] response = client.invokeOp(targetNamesPace, opName, opArgs, opReturnType);
if (response != null && response.length > 0)
{
System.out.println(response.length);
for(Object obj : response)
{
Person model = (Person)obj;
System.out.println(model.getName());
}
} } catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}
2.3 要引用的jar包有
.classpath文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="lib/axiom-impl-1.2.13.jar"/>
<classpathentry kind="lib" path="lib/axis2-adb-1.6.2.jar"/>
<classpathentry kind="lib" path="lib/axis2-kernel-1.6.2.jar" sourcepath="C:/Users/zhujinrong/.m2/repository/org/apache/axis2/axis2-kernel/1.6.2/axis2-kernel-1.6.2-sources.jar"/>
<classpathentry kind="lib" path="lib/axis2-transport-http-1.6.2.jar"/>
<classpathentry kind="lib" path="lib/axis2-transport-local-1.6.2.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
<classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.0.jar"/>
<classpathentry kind="lib" path="lib/neethi-3.0.2.jar"/>
<classpathentry kind="lib" path="lib/wsdl4j-1.6.2.jar"/>
<classpathentry kind="lib" path="lib/XmlSchema-1.4.7.jar"/>
<classpathentry kind="lib" path="lib/axiom-api-1.2.13.jar"/>
<classpathentry kind="lib" path="lib/activation-1.1.jar"/>
<classpathentry kind="lib" path="lib/axis2-adb-codegen-1.6.2.jar"/>
<classpathentry kind="lib" path="lib/axis2-java2wsdl-1.6.2.jar"/>
<classpathentry kind="lib" path="lib/mail-1.4.jar"/>
<classpathentry kind="lib" path="lib/woden-api-1.0M9.jar"/>
<classpathentry kind="lib" path="lib/woden-impl-commons-1.0M9.jar"/>
<classpathentry kind="lib" path="lib/woden-impl-dom-1.0M9.jar"/>
<classpathentry kind="lib" path="lib/wstx-asl-3.2.9.jar"/>
<classpathentry kind="lib" path="lib/xmlbeans-2.3.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 执行结果
3.1 查看服务器启动


3.2 客户端

3.3 服务端情况

3.4 直接查询

axis2 webService开发指南(2)的更多相关文章
- axis2 webService开发指南(1)
参考文件:blog.csdn.net/IBM_hoojo http://hoojo.cnblogs.com/ 1 WebService简介 WebService让一个程序可以透明的调用互联网的程序,不 ...
- axis2 webService开发指南(3)
复杂对象类型的WebService 这次我们编写复杂点的WebService方法,返回的数据是我们定义属性带getter.setter方法JavaBean,一维数组.二维数组等 1.服务源代码 新建一 ...
- eclipse+axis2+webservice开发实例
myeclipse10安装axis2插件 第一步:下载axis2-1.6的插件压缩包,axis2-eclipse-codegen-plugin-1.6.2.zip 和 axis2-eclipse-se ...
- WebService开发指南
WebServiceInAurora Web Service Web Service是一种面向服务的架构的技术,通过标准的Web协议提供服务,目的是保证不同平台的应用服务可以互操作.在Aurora框架 ...
- 基于Myeclipse+Axis2的WebService开发实录
最近开始学习了下在Myeclipse开发工具下基于WebSerivce的开发,下面将相关相关关键信息予以记录 Myeclipse的安装,本文以Myeclipse2014-blue为开发环境,相关配置执 ...
- Axis2 webservice入门--写个简单的webservice
上一篇介绍了webservice开发前的准备.下面开始写webservice.如果不了解axis2请看上一篇,如果是新手:建议一边看一边写代码,自己动手完成这个过程. 一.新建一个web项目 二.新建 ...
- axis1,xfire,jUnit 测试案列+开Web Service开发指南+axis1.jar下载 代码
axis1,xfire,jUnit 测试案列+Web Service开发指南(中).pdf+axis1.jar下载 代码 项目和资源文档+jar 下载:http://download.csdn. ...
- Webservice开发概念
一.Web Service基本概念 Web Service由两部分组成 SOAP--Web Service之间的基本通信协议. WSDL--Web Service描述语言,它定义了Web Servic ...
- ASP.NET Aries 开源开发框架:开发指南(一)
前言: 上周开源了Aries开发框架后,好多朋友都Download了源码,在运行过程里,有一些共性的问题会问到. 所以本篇打算写一下简单的开发指南,照顾一下不是太看的懂源码的同学,同时也会讲解一下框架 ...
随机推荐
- For input string: "null"
java.lang.NumberFormatException: For input string: "null" 在开发中你是否遇到过这样的问题,不管请求到的值是什么都能进入不为 ...
- lydsy个人代码.zip
/s/12vaj9vUNLMlEPxlhw4xRwA ryap 感谢@yirannn 省选前++rp
- Nchan 实时消息 安全配置
备注: 即时消息的安全对于我们来说是比较重要的,作者在设计Nchan 的时候已经考虑了 a. nchan_authorize_request (Hooks and Callbacks)可以集成 ...
- C语言控制台窗体图形界面编程(八):鼠标事件
上次讲的是键盘事件,这次我们介绍鼠标事件. 以下先介绍下鼠标事件的结构体以及相关信息. typedef struct _MOUSE_EVENT_RECORD //鼠标事件结构体 { CO ...
- 老齐python-基础5(运算符、语句)
1.运算符 1.1算术运算符 1.2比较运算符 >>> a = 10 >>> b = 20 >>> a > b False >> ...
- cocos2d js的一些tip
cocos2d-js-v3.2-rc0 cc.director.end();//退出app cc.Application.getInstance().openURL("http://www. ...
- 基于标准库的string类实现简单的字符串替换
感觉基本功还是不扎实,虽然能做些程序但是现在看来我还是个初学者(primer),试着完成习题结果还得修修改改. 废话不多说,实现功能很简单,<C++ Primer>9.5.2节习题. // ...
- Java-Runoob:Java Character 类
ylbtech-Java-Runoob:Java Character 类 1.返回顶部 1. Java Character 类 Character 类用于对单个字符进行操作. Character 类在 ...
- AbstractQueuedSynchronizer原理分析
AbstractQueuedSynchronized 以下简称AQS,是用来构建锁或者其他同步组件的基础框架. 在AQS中,为锁的获取和释放提供了一些模板方法,而实现锁的类(AQS的子类)需要实现这些 ...
- Log4j.xml配置(rolling示例)
Log4j.xml配置(很详细) <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4 ...