1.新建一个项目动态web项目Axis2Server。
2.解压缩下载的axis2-1.7.4-war.zip文件--〉axis2-1.7.4-war--〉axis2.war--〉axis2,找到WEB-INF文件,将其下边的lib、conf、modules、include、views(include和views用来列举提供的服务列表)五个文件夹复制,并粘贴到Axis2Server项目下的WEB-INF文件夹下。
3.新建service配置文件,在Axis2Server项目下的WEB-INF文件夹创建services文件夹,在其下新建wondersoftservice文件夹(名字可随意),再wondersoftservice文件夹下新建META-INF文件夹,再在新建的META-INF文件夹下创建services.xml。
4.写service方法,在src下新建com.wondersoft.webservice包,并在其下新建TestWSService.Java类。代码如下:
5.配置service,打开第3步新建的services.xml文件,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- 访问地址中的访问那个webservice的名字 -->
<serviceGroup>
<service name="TestWSService">
<description>TestWSService</description>
<parameter name="ServiceClass">
com.wondersoft.webservice.TestWSService
</parameter>
<operation name="sum">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>
</serviceGroup>
<!-- 访问地址中的访问那个webservice的名字 -->
<serviceGroup>
<service name="TestWSService">
<description>TestWSService</description>
<parameter name="ServiceClass">
com.wondersoft.webservice.TestWSService
</parameter>
<operation name="sum">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>
</serviceGroup>
在web.xml配置文件下加入如下代码:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://Java.sun.com/dtd/web-app_2_3.dtd" >
- <web-app>
- <servlet>
- <servlet-name>AxisService2</servlet-name>
- <servlet-class>
- org.apache.axis2.transport.http.AxisServlet
- </servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>AxisService2</servlet-name>
- <url-pattern>/service/*</url-pattern>
- </servlet-mapping>
- </web-app>
6.发布项目,访问
http://127.0.0.1:8080/Axis2Server/services/listServices
http://127.0.0.1:8080/Axis2Server/services/TestWSService?wsdl