1,下载axis2-1.6.1-bin.zip,axis2-1.6.1-war.zip
2,安装axis2。将axis2-1.6.1-war.zip解压后的axis2.war文件放到tomcat的webapps目录下
3,启动tomcat.在浏览器输入http://127.0.0.1:8080/axis2/ (端口按实际改)如果看到如下图,证明安装成功:
4,书写服务端:
创建services.xml文件放于META-INF文件夹下,创建MyServer.java文件
- <service name="MyService" scope="application">
- <description>
- POJO: MyService
- </description>
- <messageReceivers>
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
- class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
- class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
- </messageReceivers>
- <parameter name="ServiceClass">server.MyServer</parameter>
- </service>
- <service name="MyService" scope="application">
- <description>
- POJO: MyService
- </description>
- <messageReceivers>
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
- class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
- class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
- </messageReceivers>
- <parameter name="ServiceClass">server.MyServer</parameter>
- </service>
<service name="MyService" scope="application"> <description> POJO: MyService </description> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers> <parameter name="ServiceClass">server.MyServer</parameter> </service>
ServiceClass是类的包名。
- package server;
- public class MyServer {
- public String getName(String name){
- return "你好!"+name;
- }
- }
- package server;
- public class MyServer {
- public String getName(String name){
- return "你好!"+name;
- }
- }
package server; public class MyServer { public String getName(String name){ return "你好!"+name; } }
5,打包aar文件
其实就是通过eclipse打包jar不过改成aar文件名。
6,发布webservice
进入http://127.0.0.1:8080/axis2/然后点击“Administration”通过admin用户名密码axis2登录
然后“Upload Service”上传刚刚打包的.aar文件,重启tomcat,在services下会看到刚刚发布的webservice。
7,客户端调用:
jar包;代码详细请看压缩包
<!--StartFragment -->