1. Create a new project Dynamic Web project webservice_test3.
2. Open the <tomcat installation directory >webapps/axis2/web-inf. lib,conf, Modules three folders to copy and paste into Webservice_test3 under the project Web-inf folder.
3. Create a new service profile, under the WEBSERVICE_TEST3 project, under web-inf folder creation Services folder, under which you create a new myservice folder (name is optional), and then myservice The new folder under the Meta-inf folder, and then in the new Meta-inf folder under Create Services.xml .
4. Write the service method, create a new com.lc.service package under src , and create a new Numservice.java class. The code is as follows:
/** * @author Luocheng * Test WebService Implementation Classes */public class Numservice {public Integer getsum (integer num1, integer num2) {ret Urn Num1 + num2;}}
5. ConfigurationService, open the section3Step-NewServices.xmlfile with the following code:
<!--name is the address that the URL will access--><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 >
InWeb. XMLAdd the following code to the configuration file:
<?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 order, 1 for Tomcat to load the servlet first-- <load-on-startup>1</load-on-startup></servlet><!-- Servlet-mapping is configured with the servlet's access path Servlet-name: To be the same as the above Servle-name Url-pattern: is the path prefix when the URL accesses the servlet-->< servlet-mapping><servlet-name>axisservice2</servlet-name><url-pattern>/service/*</ Url-pattern></servlet-mapping></web-app>
6. Publish the project, visit http://localhost:8080/webservice_test3/service/AxisService?wsdl
How to configure multiple service classes
In services.xml <service> jacket <servicegroup></ Servicegroup>, you can write multiple service .
<serviceGroup> <!--Service1 configuration-<service>...</service> <!--service2 Configuration-< Service>...</service></servicegroup>
The instance configuration is as follows
<!--Configure the service path--><servicegroup><!--name is the address that the URL will access--><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 Series (v)--javaweb integrated AXIS2 and multi-service configuration