1.首先在myeclipse装axis2插件,比较麻烦,各种状况。
参照了:http://blog.youkuaiyun.com/seven_zhao/article/details/6089747
2.axis2.jar包下载,地址:http://axis.apache.org/axis2/java/core/download.cgi ,我用的版本是1.5.6
3.生成服务器端工程yourProjectName
参照了:http://www.lifeba.org/arch/java_axis2_webservice.html 使用第三部分:独立部署中的方法。
主要是复制WEB-INFO下的3个axis2相关文件夹和web.xml,然后修改services.xml里边的服务名称yourServiceName和方法名称yourMethod。
如:服务类TestWs:
package ws;
public class TestWs {
public String showName(String name) {
return name;
}
public String getName() {
return "Hello,Axis2,,by getName method.";
}
}
services.xml配置如下:
<service name="AxisService">
<description>AxisService</description>
<parameter name="ServiceClass">ws.TestWs</parameter>
<operation name="showName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<operation name="getName">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>
工程名称为Axis2Service
部署在tomcat下验证服务是否正常:
http://localhost:81/yourProjectName/services/yourServiceName?wsdl
http://localhost:81/Axis2Service/services/AxisService?wsdl
4.生成客户端测试程序
使用装好的axis2插件“Axis2 Code Generator” 生成代码到指定工程下。
测试类:
package test;
import ws.AxisServiceStub;
public class ClientTest {
public static void main(String[] args) throws Exception {
AxisServiceStub stub = new AxisServiceStub();
AxisServiceStub.ShowName command = new AxisServiceStub.ShowName();
command.setName("Hello,axis2,,by showName method.");
String showNameRtn = stub.showName(command).get_return();
System.out.println(showNameRtn);
String getNameRtn = stub.getName().get_return();
System.out.println(getNameRtn);
}
}
输出:
Hello,axis2,,by showName method.
Hello,Axis2,,by getName method.