先实现一个POJO类,代码如下:
public class MyService
{
public String getGreeting(String name)
{
return "您好 " + name;
}
public void update(String data)
{
System.out.println("<" + data + ">已经更新");
}
}
<description>
Web Service例子
</description>
<parameter name="ServiceClass">
service.MyService
</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>
在windows控制台中进入ws目录,并输入如下的命令生成.aar文件(实际上,.jar文件也可以发布webservice,但axis2官方文档中建议使用.aar文件发布webservice):
最后将ws.aar文件复制到<Tomcat安装目录>\webapps\axis2\WEB-INF\services目录中,启动Tomcat后,就可以调用这个WebService了。调用的方法和《WebService大讲堂之Axis2(1):用POJO实现0配置的WebService》所讲的方法类似。
<description>
Web Service例子
</description>
<parameter name="ServiceClass">
service.MyService
</parameter>
<operation name="getGreeting">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<operation name="update">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
</operation>
</service>
public class MyService1
{
public String getName()
{
return "bill";
}
}
<service name="myService">
<description>
Web Service例子
</description>
<parameter name="ServiceClass">
service.MyService
</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>
<service name="myService1">
<description>
Web Service例子
</description>
<parameter name="ServiceClass">
service.MyService1
</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>
</serviceGroup>