- 浏览: 173329 次
- 性别:
- 来自: 厦门
文章分类
- 全部博客 (186)
- Ant (11)
- Axis2 (15)
- Car (9)
- Eclipse (1)
- Java (19)
- Java-EM (4)
- Javascript (11)
- Jsp (1)
- Hibernate (9)
- Mysql (1)
- Ms-Dos (5)
- Music (0)
- Oracle (3)
- Postgresql (0)
- Photoshop (1)
- Spring (17)
- Struts (8)
- Selenium (5)
- Ubuntu (13)
- News (17)
- Others (7)
- SSH (11)
- 算法 (5)
- FreeMarker (4)
- Tomcat (2)
- Linux (5)
最新评论
基于Axis2开发WebService代码详解
关键字: webservice转载:http://tenn.iteye.com/blog/100755
1.HelloWorld做了些什么?
HelloWorld功能非常简单,在客户端输入你的姓名,本例中为ZJ。参数传递到服务器端后,经过处理将返回name+"HelloWorld!",本例中为ZJ HelloWorld!
2.服务器端文件HelloWorld.java
HelloWorld.java
3.services.xml部署文件
services.xml
注解:消息交换模式。
目前Axis2支持三种模式:In-Only、Robust-In和In-Out。In-Only消息交换模式只有SOAP请求,而不需要应答; Robust-In消息交换模式发送SOAP请求,只有在出错的情况下才返回应答;In-Out消息交换模式总是存在SOAP请求和应答。本例使用In- Out模式。
4.客户端文件TestClient.java
5.Axis2简介
Apache Axis2 是Axis的后续版本,是新一代的SOAP引擎。Axis2的主要特点有:
1)采用名为 AXIOM(AXIs Object Model)的新核心 XML 处理模型,利用新的XML解析器提供的灵活性按需构造对象模型。
2)支持不同的消息交换模式。目前Axis2支持三种模式:In-Only、Robust-In和In-Out。In-Only消息交换模式只有 SOAP请求,而不需要应答;Robust-In消息交换模式发送SOAP请求,只有在出错的情况下才返回应答;In-Out消息交换模式总是存在 SOAP请求和应答。
3)提供阻塞和非阻塞客户端 API。
4)支持内置的 Web服务寻址 (WS-Addressing) 。
5)灵活的数据绑定,可以选择直接使用 AXIOM,使用与原来的 Axis 相似的简单数据绑定方法,或使用 XMLBeans、JiBX 或 JAXB 2.0 等专用数据绑定框架。
6)新的部署模型,支持热部署。
7)支持HTTP,SMTP,JMS,TCP传输协议。
8)支持REST (Representational State Transfer)。
6.Axis2 支持的规范包括:
-SOAP 1.1 and 1.2
-Message Transmission Optimization Mechanism (MTOM), XML Optimized Packaging (XOP) and SOAP with Attachments
-WSDL 1.1, including both SOAP and HTTP bindings
-WS-Addressing (submission and final)
-WS-Policy
-SAAJ 1.1
有关Axis2更加详细的介绍,可以访问Axis2网站http://ws.apache.org/axis2/。
1.HelloWorld做了些什么?
HelloWorld功能非常简单,在客户端输入你的姓名,本例中为ZJ。参数传递到服务器端后,经过处理将返回name+"HelloWorld!",本例中为ZJ HelloWorld!
2.服务器端文件HelloWorld.java
HelloWorld.java
- 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;
- }
- }
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; } }
3.services.xml部署文件
services.xml
- <?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>
<?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>
注解:消息交换模式。
目前Axis2支持三种模式:In-Only、Robust-In和In-Out。In-Only消息交换模式只有SOAP请求,而不需要应答; Robust-In消息交换模式发送SOAP请求,只有在出错的情况下才返回应答;In-Out消息交换模式总是存在SOAP请求和应答。本例使用In- Out模式。
4.客户端文件TestClient.java
- TestClient.java
- 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();
- }
- }
- }
TestClient.java 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(); } } }
5.Axis2简介
Apache Axis2 是Axis的后续版本,是新一代的SOAP引擎。Axis2的主要特点有:
1)采用名为 AXIOM(AXIs Object Model)的新核心 XML 处理模型,利用新的XML解析器提供的灵活性按需构造对象模型。
2)支持不同的消息交换模式。目前Axis2支持三种模式:In-Only、Robust-In和In-Out。In-Only消息交换模式只有 SOAP请求,而不需要应答;Robust-In消息交换模式发送SOAP请求,只有在出错的情况下才返回应答;In-Out消息交换模式总是存在 SOAP请求和应答。
3)提供阻塞和非阻塞客户端 API。
4)支持内置的 Web服务寻址 (WS-Addressing) 。
5)灵活的数据绑定,可以选择直接使用 AXIOM,使用与原来的 Axis 相似的简单数据绑定方法,或使用 XMLBeans、JiBX 或 JAXB 2.0 等专用数据绑定框架。
6)新的部署模型,支持热部署。
7)支持HTTP,SMTP,JMS,TCP传输协议。
8)支持REST (Representational State Transfer)。
6.Axis2 支持的规范包括:
-SOAP 1.1 and 1.2
-Message Transmission Optimization Mechanism (MTOM), XML Optimized Packaging (XOP) and SOAP with Attachments
-WSDL 1.1, including both SOAP and HTTP bindings
-WS-Addressing (submission and final)
-WS-Policy
-SAAJ 1.1
有关Axis2更加详细的介绍,可以访问Axis2网站http://ws.apache.org/axis2/。
发表评论
-
Spring Web Service 学习之Hello World篇2
2008-11-03 15:32 10356, 修改配置文件spring-ws- ... -
webservice之axis2方式开发总结
2008-11-04 09:33 691webservice之axis2方式开发总结 关键字: we ... -
基于Tomcat5.0和Axis2开发Web Service应用实例
2008-11-04 09:38 736基于Tomcat5.0和Axis2开发Web Service应 ... -
使用Axis2来构建Web Service客户端
2008-11-04 09:46 730使用Axis2来构建Web Service客户端 2 ... -
webservice-之使用axis+spring开发
2008-11-04 17:42 601... -
webservice-之使用axis+spring开发2
2008-11-04 17:42 770三、配置文件 (全部放在 ... -
Axis 开发WebService
2008-11-04 18:16 694Axis 开发WebService Axis 开发WebSe ... -
spring与axis的整合
2008-11-04 18:23 669spring与axis的整合 eclipse resin ax ... -
在Eclipse中创建基于Axis2的web services
2008-11-05 09:04 1003本实验的目的是让你尽可能快的创建使用 Axis2 的服务和客户 ... -
Axis2快速上手指南
2008-11-05 09:06 685本指南的目的是让你尽可能快的创建使用Axis2的服务和客户端, ... -
Axis2快速上手指南2
2008-11-05 09:07 663创建服务 在这个部分,我们将看看根据StockQuoteSe ... -
Axis2快速上手指南4
2008-11-05 09:08 824使用ADB生成一个客户端 执行以下步骤来使用Axis Dat ... -
Axis2 Integration With The Spring Framework
2008-11-05 09:16 844Axis2 Integration With The Spri ... -
定义web service接口的十点注意事项
2008-11-05 14:03 1208一、接口是自说明的。 也就是说,接口的名字、参数和返回值在一看 ...
相关推荐
Axis2开发webservice总结
今天特意将项目中用Axis2集成SSH实现WebService的过程记录下来,一方面做一下笔记,另一方面,方便广大码农朋友,希望能跟大家交流学习。 本文介绍用Axis2集成SSH搭建WebService。会达到的效果: 1.按照传统我们用...
Axis2开发webservice案例详解-附件资源
Axis2是目前比较流行的WebService引擎。WebService被应用在很多不同的场景
里面包含用到的axis的jar包 和一个java文件,下载后,将文件放在工程下,添加jar包即可运行,用的开源的webservice服务,里面重要代码都做了注释。
Axis2集成SSH搭建WebService支持事务(图文详解含核心代码).zip
java 开发 webservice axis2 方式详解。 附带详细说明文档 配置 ,
详细介绍使用axis开发webservice服务,有axis帮组手册,还有例子
基于Axis2_Web_Service的Eclipse_BPEL使用详解
总结用axis2发布项目总结,有一些是前辈的,只是在这里做了总结而已。新人愚见,多多包涵。
如果初识axis发布/调用WS,建议先读上面的参考文件,本文对于发布/调用WS的主要步骤只是简单文字描述,没有它写的详尽
axis和Soap方式调用Webservice服务完整代码。java的。
在eclipse用axis插件开发websservice步骤 详解
主要介绍了Java编程Webservice指定超时时间代码详解,简单介绍了webservice,然后分享了通过使用JDK对Webservice的支持进行Webservice调用实现指定超时时间完整示例,具有一定借鉴价值,需要的朋友可以参考下。
WebService经典24篇网文汇总,包含axis2_Xfire搭建_WSDL详解_自动生成客户端和WSDL等,自己找了好久的内容; 都是自己学习过程中网络的知识,找了很久,里边有一些自己的标记,如果发现chm内容是空白,注意看一下,其实是...