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了源码,在运行过程里,有一些共性的问题会问到. 所以本篇打算写一下简单的开发指南,照顾一下不是太看的懂源码的同学,同时也会讲解一下框架 ...
随机推荐
- json对象和json字符串相互转换
1.将JSON字符串转换为JSON对象 var data = JSON.parse(str); // JSON.parse();方法 console.log(data.name); 2.将JSON对象 ...
- 关于MySQL 通用查询日志和慢查询日志分析
MySQL中的日志包括:错误日志.二进制日志.通用查询日志.慢查询日志等等.这里主要介绍下比较常用的两个功能:通用查询日志和慢查询日志. 1)通用查询日志:记录建立的客户端连接和执行的语句. 2)慢查 ...
- grpc 安装以及墙的解决方法
1. 默认官方文档 go get -u google.golang.org/grpc 因墙的问题,大部分安装是无法完成的 2. 解决方法 a. grpc mkdir -p $GOAPTH/src/go ...
- luarocks yum 安装引起的lapis lua 包查找问题(centos7版本)
备注: 大家在进行lapis 开发的时候有些人比较懒直接使用yum 按照luarocks,之后 使用luarocks 安装lapis 一般来说对于linux 64位的环境都会有些问题(包找 ...
- LuaJavaBridge
http://www.360doc.com/content/14/0117/13/9200790_345940368.shtml quick目录结构介绍 http://cn.cocos2d-x.org ...
- Java连接MySQL数据库和Oracle数据库并进行简单的SQL操作的一次尝试
MySQL和Oracle的JDBC的maven dependency如下: <!-- mysql --> <dependency> <groupId>mysql&l ...
- Django 组件-cookie与session
Cookie概述 什么叫Cookie Cookie翻译成中文是小甜点,小饼干的意思.在HTTP中它表示服务器送给客户端浏览器的小甜点.其实Cookie是key-value结构,类似于一个python中 ...
- js正则表达式验证大全--转载
转载来源:http://www.cnblogs.com/hai-ping/articles/2997538.html#undefined //判断输入内容是否为空 function IsNull(){ ...
- [Java.Web]从零开始布署 Tomcat
1. 下载 JRE 1.7 2. 下载 Tomcat 7.0.77,我使用的是红圈的压缩包版本,也可以使用绿圈的安装包版本[更省心] 3. 加入环境变量 JRE_HOME .CATALINA_HOME ...
- HDU1257题解
解题思路:这题的本质就是:求一个给定的数字序列中,非递增(或非递减)子序列的最少的条数. 思维误区:本题很容易被样例坑,以为是直接求跳跃点(i < j && ai < aj ...