1.HelloWorld做了些什么?
HelloWorld功能非常简单,在客户端输入你的姓名,本例中为Leo。参数传递到服务器端后,经过处理将返回name+"HelloWorld!",本例中为Leo HelloWorld!
2.服务器端文件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; } }
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>
注解:消息交换模式。
目前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("Leo"); 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/。
相关推荐
网上很流行的一个文档,axis的一个helloworld开发,源文档中有四处错误,经本人修改后重新发布,eclipse调试通过
axis2服务端的各种写法及客户端的用法及helloworld代码,包配环境部署文件axis2.war 其中 services文件 - - <!-- 实现的服务类,locked 锁定 xsd:false 一种格式 --> ...
------原来图中有个图切错了,... Helloworld helloworld=new Helloworld(); helloworld.setName("zgx---"); HelloworldResponse resp= helloStub.helloworld(helloworld); System.out.println(resp.get_return());
使用myeclipse8.5安装axis2插件... Helloworld helloworld=new Helloworld(); helloworld.setName("zgx---"); HelloworldResponse resp= helloStub.helloworld(helloworld); System.out.println(resp.get_return());
使用axis2技术编写的webservice接口实例,直接放在应用服务器下便可使 用http://localhost:xxxx/axis2/service/来访问WSDL 业务源代码位于\WEB-INF\classes\HelloWorld.java
NULL 博文链接:https://bepatient.iteye.com/blog/798913
axis1实现helloWorld 博文链接:https://yehao0716.iteye.com/blog/1535268
此压缩包不仅仅只有文档,还有axis1.4相关资源。详细描述了如何在tomacat6.0下发布webService,并以此为基础,进一步...而且网上多半是一些helloworld的范例,但实际项目工程的发布又和发布helloworld范例是不同的。
TOMCAT+AXIS进行WEBSERVICE开发的配置和HELLOWORLD程序