annotation tags for Java

Source: Internet
Author: User

Simply use Java's annotation tags to publish standard Java methods as Web service, but not all Java classes can be published as Web service. Java class to be a bean that implements a Web service, it needs to follow these guidelines:

  • This class must be a public class

  • These classes cannot be final or abstract.

  • This class must have a public default constructor

  • This class must never have a finalize () method


    Annotation [email protected] (name= "Example", targetnamespace= "Http://www.jsoso.com/wstest", servicename= " Example ")
    @WebService tags primarily expose classes as WebService, where the targetnamespace attribute defines its own namespace, ServiceName defines < definitions > tags and <service The Name property of the > tag.

    Annotation 2: @SOAPBinding (STYLE=SOAPBINDING.STYLE.RPC)
    The @SOAPBinding tag defines the message protocol for SOAP in the WSDL document, where the Style property corresponds to the document type of the soap, optionally with RPC and document

    Annotation 3: @WebMethod (operationname= "Tosayhello", action= "SayHello", Exclude=false)
    @WebMethod define how the Web service works,
    Property action corresponds to the activity of the action, such as <soap:operation soapaction= "SayHello"/>
    The OperationName property matches the name of the wsdl:operation, such as <operation name= "Tosayhello" parameterorder= "UserName" >
    Property exclude is used to prevent an inherited method from being exposed as a Web service, false by default

    Annotation 4: @WebResult (name= "Returnword")
    @ Webresult defines a method that returns a worthy name, such as <part name= "Returnword" type= "xsd:string"/>

    Annotation 5: @WebParam (partname= "person", mode=mode.in
    @WebParam defines the parameter name of the method, such as <part name= "person" type= "Tns:person"/&gt, where the Mode property represents the direction of the parameter, and the optional value is In/out/inout

  • Package org.jsoso.jws.server;    import java.util.arraylist;  import  javax.jws.WebMethod;  import javax.jws.WebParam;  import  javax.jws.webresult;  import javax.jws.webservice;  import  javax.jws.webparam.mode;  import javax.jws.soap.soapbinding;  /   *   Class    */   @WebService for WebService services (name= "Example",  targetnamespace= "http:/ /www.jsoso.com/wstest ",  servicename=" Example ")    @SOAPBinding (STYLE=SOAPBINDING.STYLE.RPC)    public class Example {      private ArrayList< Person> persons = new arraylist<person> ();       /**      *        *  returns a string       *  @param  username      *  @return       */        @WebMethod (operationname= "Tosayhello", action= "SayHello", Exclude=false)         @WebResult (name= "Returnword")//Customize the description of the method return value in the WSDL related       public  String sayhello (@WebParam (name= "UserName") string username)  {           return  "Hello:" &NBSP;+&NBSP;USERNAME;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}         /**      * web  The return value of the services  method and the type of the parameter cannot be interface       *  @param  person       *  @return       *  @throws  HelloException       */       @WebMethod (operationname= "SayHello",  action= "SayHello")        @WebResult (partname= "personlist")       public person[]  sayhello (@WebParam (partname= "person",  mode=mode.in) person person,                string username)  throws  helloexception {          if  (person ==  null | |  person.getname ()  == null)  {               throw new helloexception ("Say hello error, the image is empty. ");          }           system.out.println (Person.getname ()  +  "  to  "  + username +   "  said Hello, I am this year"  + person.getage ()  +  "Years");           persons.add (person);   &Nbsp;       return persons.toarray (new person[0]);       }  }


annotation tags for Java

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.