标签:gets mod .net == rtu sage inf doctype utf-8
1.新建一个项目动态web项目webservice_test3。
2.打开<Tomcat安装目录>webapps/axis2/WEB-INF,将lib、conf、modules三个文件夹复制,并粘贴到webservice_test3项目下的WEB-INF文件夹下。
3.新建service配置文件,在webservice_test3项目下的WEB-INF文件夹创建services文件夹,在其下新建myservice文件夹(名字可随意),再myservice文件夹下新建META-INF文件夹,再在新建的META-INF文件夹下创建services.xml。
4.写service方法,在src下新建com.lc.service包,并在其下新建NumService.java类。代码如下:
/** * @author luocheng * 测试webservice实现类 */ public class NumService { public Integer getSum(Integer num1, Integer num2) { return num1 + num2; } }5.配置service,打开第3步新建的services.xml文件,代码如下:
<!-- name是url将访问的地址 --> <service name="AxisService"> <description>AxisService</description> <parameter name="ServiceClass"> com.lc.service.NumService </parameter> <operation name="sum"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> </service>在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> <!-- 加载顺序,1代表tomcat最先加载该servlet --> <load-on-startup>1</load-on-startup> </servlet> <!-- servlet-mapping配置的是servlet的访问路径 servlet-name:要和上面的servle-name相同 url-pattern:是URL访问该servlet时的路径前缀 --> <servlet-mapping> <servlet-name>AxisService2</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> </web-app>6.发布项目,访问http://localhost:8080/webservice_test3/service/AxisService?wsdl
多个service类的配置方法
在services.xml中<service>外套上<serviceGroup></serviceGroup>,就可以写多个service了。
<serviceGroup> <!--service1配置--> <service>...</service> <!--service2配置--> <service>...</service> </serviceGroup>实例配置如下
<!-- 配置service路径 --> <serviceGroup> <!-- name是url将访问的地址 --> <service name="AxisService"> <description>AxisService</description> <parameter name="ServiceClass"> com.lc.service.NumService </parameter> <operation name="sum"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <operation name="dVal"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> </service> <service name="TestService2"> <description>TestService2</description> <parameter name="ServiceClass"> com.lc.service2.TestService2 </parameter> <operation name="append"> <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> </service> </serviceGroup>
webservices系列(五)——javaweb整合Axis2及多service配置
标签:gets mod .net == rtu sage inf doctype utf-8
原文地址:http://blog.csdn.net/luo4105/article/details/70182451