基于Tomcat5.0和Axis2开发Web Service代码详解
package sample;
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 {
//读取client端getSayHelloOMElement()方法传递的参数in。
public OMElement sayHello(OMElement in){
//将in转换为String。
String name=in.getText();
String info=name+"HelloWorld!";
//创建response SOAP包。
OMFactory fac=OMAbstractFactory.getOMFactory();
// OMNamespace指定此SOAP文档名称空间。
OMNamespace omNs=fac.createOMNamespace("http://helloworld.com/","hw");
//创建元素sayHello,并指定其在omNs指代的名称空间中。
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>
// ServiceClass指定Java Class的位置,即实现服务的类。
<parameter name="ServiceClass" locked="false">sample.HelloWorld</parameter>
// operation 与Java Class中方法名对应。
<operation name="sayHello">
// messageReceiver看下文注解。
<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 {
// targetEPR指定打包的Service(.aar文件)在容器中的物理位置。
private static EndpointReference targetEPR=new EndpointReference
("http://localhost:8080/axis2/services/HelloWorld");
public static OMElement getSayHelloOMElement(){
//创建request SOAP包。
OMFactory fac=OMAbstractFactory.getOMFactory();
// OMNamespace指定此SOAP文档名称空间。
OMNamespace omNs=fac.createOMNamespace("http://helloworld.com/","hw");
//创建元素sayHello,并指定其在omNs指代的名称空间中。
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();
//发出request SOAP,
//同时将得到的远端由sayHello方法返回的信息保存到result。
//通过services.xml能准确找到sayHello方法所在的文件。
OMElement result=sender.sendReceive(sayHello);
}
catch(Exception axisFault){
axisFault.printStackTrace();
}
}
}
|
相关介绍
基于Tomcat5.0和Axis2开发Web Service应用实例
转载于:https://blog.51cto.com/zhangjunhd/23692
基于Tomcat5.0和Axis2开发Web Service代码详解相关推荐
- 基于Tomcat5.0和Axis2开发Web Service应用实例
本文将介绍如何使用Tomcat5.0和Apache Axis2开发.部署及测试一个简单的Web Service应用.<?xml:namespace prefix = o ns = "u ...
- 基于RK3399ESP8285自动售货柜项目—MP08开发板端代码详解
基于RK3399&ESP8285自动售货柜项目-②MP08开发板端代码详解 本系列文章将详细讲解该基于RK3399及ESP8285自动售货柜的完整实现方法,从硬件连接到网络通信再到软件实现,本 ...
- 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?" 本文参考网上众多资料,有的也不知源作者是谁,就不一一列举了 ...
- IOTOS物联中台从0到1开发modbus_rtu驱动 实例详解
本文章为原创,转载请注明出处! 登录平台:IOTOS®爱投斯物联中台 账号:iotos_test 密码:iotos123 代码地址:IOTOSDK-Python: IOTOS Python版本S ...
- 基于PyTorch的TinyMind 汉字书法识别部分代码详解
文章目录 0. 前言 1 遇到的问题 1.1 NameError: name 'cv2' is not defined 1.1.1 OpenCV下载 1.1.2 OpenCV安装 打开Anacoda3 ...
- 基于机器学习的恶意样本静态检测的代码详解(ember)
文章目录 1. 类与类之间的关系 2. 每个类的详细分析 2.1 ByteHistogram 2.2 ByteEntropyHistogram 2.3 SectionInfo 2.4 ImportsI ...
- [Axis2与Eclipse整合开发Web Service系列之三] 服务端返回值
前言 在前面的三篇中 [Axis2与Eclipse整合开发Web Service系列之一] 生成Web Service Client(将WSDl 转化成 Java代码) [Axis2与Eclipse整 ...
最新文章
- 华东师范计算机入门平时作业,计算机入门模拟卷A-华东师范大学.doc
- K8S 1.9.0二进制包部署(五)
- linux c 下信号量 windows下event_windows和linux下配置jdk环境
- 二分类神经网络的特征光谱---1-2至1-9
- sql between包括两端吗_简单查询-SQL
- [视频教程] 配置mysql用户的权限并查询数据
- CF452F Permutations/Luogu2757 等差子序列 树状数组、Hash
- ANSYS2020R2与Solidworks2019进行关联,但2019安装完后打开出现无法获得下列许可SOLIDWORKS Standard.使用许可文件不支持此版本(-21,126,0)
- centos 7 网络设置与图像化界面下载
- Oracle数据到MaxCompute乱码问题详解
- Gradle 2.3 发布
- 优化浏览器默认scroll样式小技巧
- 《深度学习笔记》——“损失函数loss乘以正数因子a是否等价于学习率lr乘以a呢?”
- Google统治桌面再进一步 欲重走微软称霸之路
- 数据库服务器位置,怎么查看服务器数据库的位置
- 怎样缩小图片大小kb?
- 拓嘉启远:拼多多店铺子账号设置,提高店铺效率
- ubuntu 10.04 trackpoint
- 百度地图定位功能的错误has leaked ServiceConnection 解决
- HTML5字体设置重影,Word怎么设置字体重影