1. What did HelloWorld do?
HelloWorld function is very simple, in the client input your name, in this case, ZJ. After the parameter is passed to the server, the processing will return name+ "helloworld!", in this case ZJ helloworld!
2. Server-side file 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;
}
}
3. Services.xml Deployment Files
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>
Annotation: Message exchange Mode.
Currently, AXIS2 supports three modes: In-only, robust-in and In-out. The IN-ONLY message exchange Mode is a SOAP request, not a response, a robust-in message exchange Mode that sends a SOAP request and returns an answer only if there is an error; in-out the message exchange Mode always has a SOAP request and an answer. This example uses In-out mode.