如下例子
package com.wm5920.webservice; public class HelloService { public String sayHello(){ return "hello"; } public String sayHelloToPerson(String name){ if(name==null){ name = "nobody"; } return "hello,"+name; } public void updateData(String data){ System.out.println(data+" 已更新。"); } }
services.xml配置一:
<?xml version="1.0" encoding="UTF-8"?> <service name="HelloService"> <description> Web Service例子 </description> <parameter name="ServiceClass"> com.wm5920.webservice.HelloService </parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> </messageReceivers> </service>
services.xml配置二:
配置1是为具体的操作方法指定消息接收器,配置2是<span style="color: rgb(51,51,51); font-family: Arial; line-height: 26px;">服务级消息接收器。推荐使用配置2</span>
<span style="color: rgb(51,51); font-family: Arial; line-height: 26px;">在部署时,Axis2会自动给操作选择正确的消息接收器,不用像配置1每个操作都要配置</span>
<span style="color: rgb(51,51); font-family: Arial; line-height: 26px;"> </span>
<service name=" HelloService"> <description> Web Service例子 </description> <parameter name="ServiceClass"> com.wm5920.webservice.HelloService </parameter> <operation name="sayHello"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </operation> <operation name="sayHelloToPerson"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </operation> <operation name="updateData"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> </operation> </service>