基于Tomcat5.0和Axis2开发Web Service应用实例
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
public class HelloWorld {
public OMElement sayHello(OMElement in){
String name=in.getText();
String info=name+"HelloWorld!";
OMFactory fac=OMAbstractFactory.getOMFactory();
OMNamespace omNs=fac.createOMNamespace("http://helloworld.com/","hw");
OMElement resp=fac.createOMElement("sayHelloResponse",omNs);
resp.setText(info);
return resp;
}
}
|
<?xml version="1.0" encoding="UTF-8"?>
<service name="HelloWorld">
<description>
This is a sample Web Service.
</description>
<parameter name="ServiceClass" locked="false">sample.HelloWorld</parameter>
<operation name="sayHello">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
</service>
|
package example.client;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
public class TestClient {
private static EndpointReference targetEPR=new EndpointReference
("http://localhost:8080/axis2/services/HelloWorld");
public static OMElement getSayHelloOMElement(){
OMFactory fac=OMAbstractFactory.getOMFactory();
OMNamespace omNs=fac.createOMNamespace("http://helloworld.com/","hw");
OMElement method=fac.createOMElement("sayHello",omNs);
method.setText("ZJ");
return method;
}
public static void main(String[] args){
try{
Options options=new Options();
options.setTo(targetEPR);
ServiceClient sender=new ServiceClient();
sender.setOptions(options);
OMElement sayHello=TestClient.getSayHelloOMElement();
OMElement result=sender.sendReceive(sayHello);
System.out.println(result);
}
catch(Exception axisFault){
axisFault.printStackTrace();
}
}
}
|
<hw:sayHelloResponse xmlns:hw="http://helloworld.com/"
xmlns:tns="http://ws.apache.org/axis2">
ZJHelloWorld!
</hw:sayHelloResponse>
|
转载于:https://blog.51cto.com/zhangjunhd/23690
基于Tomcat5.0和Axis2开发Web Service应用实例相关推荐
- 基于Tomcat5.0和Axis2开发Web Service代码详解
本文将详细介绍HelloWorld中使用的server和client端代码.阅读之前,你应该首先了解SOAP1.1协议.<?xml:namespace prefix = o ns = " ...
- myeclipse下用axis2开发web service的第一个程序(SayHello)
jar包 axis.jar jaxrpc.jar saaj.jar commons-logging.jar commons-discovery.jar wsdl4j.jar SayHello是很多人都 ...
- myeclipse下用axis2开发web service
SayHello是很多人都写过的web service.实现的功能是通过web服务输出"人名,how are you?" 本文参考网上众多资料,有的也不知源作者是谁,就不一一列举了 ...
- 初体验myeclipse+Axis2 开发web service (一)转
SayHello是很多人都写过的web service.实现的功能是通过web服务输出"人名,how are you?" 本文参考网上众多资料,有的也不知源作者是谁,就不一一列举了 ...
- [Axis2与Eclipse整合开发Web Service系列之三] 服务端返回值
前言 在前面的三篇中 [Axis2与Eclipse整合开发Web Service系列之一] 生成Web Service Client(将WSDl 转化成 Java代码) [Axis2与Eclipse整 ...
- [Axis2与Eclipse整合开发Web Service系列之二] Top-Down方式,通过WSDL逆向生成服务端(续)
前言 本篇是承接上一篇: [Axis2与Eclipse整合开发Web Service系列之二] Top-Down方式,通过WSDL逆向生成服务端 在上一篇粗略地介绍了如何使用Top-Down的方式创建 ...
- [图解教程]Axis2与Eclipse整合开发Web Service之二:WSDL逆向生成服务端
[图解教程]Axis2与Eclipse整合开发Web Service之二:WSDL逆向生成服务端 一般开发Web Service,是选写服务端,再根据生成的WSDL文件生成客户端.看过一本SOA的书中 ...
- .NET使用VS2010开发Web Service
Web Service是一个面向服务的架构(SOA),不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Internet进行基于Http协议的网络应用间的交互.基于.NET平台,可以使用 ...
- JAVA开发Web Service几种框架介绍
在讲Web Service开发服务时,需要介绍一个目前开发Web Service的几个框架,分别为Axis,axis2,Xfire,CXF以及JWS(也就是前面所述的JAX-WS,这是Java6发布所 ...
最新文章
- TCP四次握手释放连接
- kaggle账号_Kaggle 数据挖掘比赛经验分享
- Foxmail记事插入的表格怎么设置单元格边距
- OJ1010: 求圆的周长和面积
- linux下dns劫持C语言实现,Linux下实现劫持系统调用的总结(上)--代码及实现
- shiro框架的UsernamePasswordToken与对应Realm中的AuthenticationToken的一点比较
- 用C语言编写约瑟夫环程序,约瑟夫环C语言,请高手检查我的程序
- 大咖来信 | 轮值董事长徐直军,复盘华为AI战略出台始末
- mysql 备份的权限_Mysql 数据库备份权限
- 给定一列非负整数,求这些数连接起来能组成的最大的数。
- 计算机硬盘突然只有一个c盘,win10硬盘消失了只剩下c盘怎么恢复_win10硬盘突然消失只有c盘解决方法-win7之家...
- workbench动力学周炬_ANSYS WORKBENCH有限元分析实例详解(动力学)
- 吉他效果器amplitube 4 mac 完整破解版永久激活方法
- python图像锐化_(python 图像锐化教程)C 实现bmp图像锐化后,锐化的效果很差,求大神帮忙啊...
- 智齿科技携手无忧我房 VR+AI新品亮相GTC
- springboot启动banner图片
- 云计算数据中心的特点
- 好用的工作邮箱有哪些?工作邮箱如何登录
- java实现lbs_Java总结篇系列:Java泛型
- linux TC命令使用总结
热门文章
- VTK:IO之DumpXMLFile
- OpenGL Texture Coordinates纹理坐标的实例
- OpenGL定向光的投影阴影
- C语言实现跳转搜索jump search算法(附完整源码)
- C语言实现hashset算法(附完整源码)
- C++基本输入/输出
- springboot整合mysql5.7_每天五分钟写K8(四):SpringBoot与mysql整合
- 史上最简单的SpringCloud教程 | 第十一篇: docker部署spring cloud项目
- 笛卡尔集基本原理,等值连接,不等值连接,外连接,自连接
- Mysql 8二进制包多实例绿色解压安装Windows配置