WebServices Study Notes (iv) publish with Services.xml file WebService

Source: Internet
Author: User
Tags soap wsdl

Iv. Publishing with Services.xml file WebService

The Java class created by the previous webservices cannot have a package name, where a configuration file Services.xml can be used to build a package name WebService

First create the MyService class, under Service package

Package Service;import Javax.jws.webparam;public class MyService {public String getgreeting (@WebParam (name= "name") String name) {return "Hello" + Name;} public void Update (@WebParam (name= "data") String data)    {        System.out.println ("<" + Data + "> updated");}    }
and build Services.xml.

<?xml version= "1.0" encoding= "UTF-8"?><!--a service element can only be published with a webservice,name representing the name of this webservice, For example, use the following URL to get the WSDL content of this webservice: the Http://localhost:8080/axis2/services/MyService?wsdl,name attribute refers to the name in front of the WSDL. It is recommended to set the same name as the class name--><service name = "MyService" ><!--description of the current WebService--><description>webservice example</description><!--set WebService corresponding class name, each parameter has a mandatory property (name) and an optional property (locked), The Locked property indicates whether the value of parameter is allowed to be overwritten by another sub-node in the hierarchy--><parameter name = "ServiceClass" >service. Myservice</parameter><messagereceivers><messagereceiver mep= "http://www.w3.org/2004/08/wsdl/ In-out "class=" Org.apache.axis2.rpc.receivers.RPCMessageReceiver "/><messagereceiver mep=" http://www.w3.org /2004/08/wsdl/in-only "            class=" Org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver "/></ Messagereceivers></service>


Some simple things to look at the comments above, here we go first. Mep--message Exchange pattern, the message exchange pattern, which defines the interchange pattern of SOAP1.2 messages between the WebServices provider and the requester.

Currently AXIS2 supports three modes: in-only, robust in-only and in-out. The IN-ONLY message exchange pattern is only a SOAP request and does not require an answer; The robust-in message exchange pattern sends a SOAP request and returns an answer only in the event of an error; The In-out message exchange pattern always has a SOAP request and a reply.

The SOAP supported modes are: In-optional-out, out-only, robust out-only, out-in, out-optional-in, etc.

Everyone can also define their own MEP, but the SOAP1.2 specification requires a unique URI assigned to each MEP to identify it.

The URI of the In-out MEP like above is Http://www.w3.org/2004/08/wsdl/in-out

The URI of the In-only MEP is http://www.w3.org/2004/08/wsdl/in-only


Publishing WebService in this way must be packaged into an. aar file, which is actually the. jar file that changed the extension. There are now two files established: Myservice.java and Services.xml. Compile the Myservice.java to generate the Myservice.class.

The location of the Services.xml and Myservice.class files is as follows:

D:\xampp\tomcat\webapps\ws\META-INF\services.xml

D:\xampp\tomcat\webapps\ws\service\MyService.class


Enter the WS directory in the Windows console and enter the following command to generate the. aar file (in fact,. jar files can also be published WebService, but the. aar file is recommended in the AXIS2 official documentation WebService):

Jar CVF Ws.aar. (Note that there is a "." In the end, which means packaging the current directory)

Finally, the Ws.aar file is copied to the <tomcat installation directory >\webapps\axis2\web-inf\services directory, and after Tomcat is started, this webservice can be called.


If you want to publish multiple webservice, you can use the <serviceGroup> element, such as building a MyService1 class

Package Servicepublic class myservice1{public    String getName ()      {         return "Bill";    }}

Services.xml as follows:

<serviceGroup> <service name= "MyService" > <description> Web Service Example </d escription> <parameter name= "ServiceClass" > Service. MyService </parameter> <messageReceivers> <messagereceiver mep= "http://www.w3.or G/2004/08/wsdl/in-out "class=" Org.apache.axis2.rpc.receivers.RPCMessageReceiver "/> <messa Gereceiver mep= "http://www.w3.org/2004/08/wsdl/in-only" class= "org.apache.axis2.rpc.receivers.RPCInOnlyMess Agereceiver "/> </messageReceivers> </service> <service name=" MyService1 "> <de            Scription> Web Service Example </description> <parameter name= "ServiceClass" > Service. MyService1 </parameter> <messageReceivers> <messagereceiver mep= "http://www.w3.o Rg/2004/08/wsdl/in-out "class=" org.apache.axIs2.rpc.receivers.RPCMessageReceiver "/> <messagereceiver mep=" Http://www.w3.org/2004/08/wsdl/in-only " class= "Org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> </messageReceivers> < /service></servicegroup>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.