WebService-use JAX-ws annotations to quickly build server and client

Source: Internet
Author: User
Tags soap wsdl

1.Define the interface

1 ImportJavax.jws.WebMethod;2 ImportJavax.jws.WebParam;3 ImportJavax.jws.WebResult;4 ImportJavax.jws.WebService;5 Importjavax.jws.soap.SOAPBinding;6 ImportJavax.jws.soap.SOAPBinding.Style;7 8 @WebService9 Ten@SOAPBinding (style =style.rpc) One  Public InterfaceIsay { A@WebMethod (operationname= "Hansayhello") -@WebResult (name= "Myreturn") -      PublicString SayHello (@WebParam (name= "name") String name); the      -@WebMethod (operationname= "Hansaygoodbye") -@WebResult (name= "Myreturn") -      PublicString Saygoodbye (@WebParam (name= "name") String name); +      -@WebMethod (exclude=true)//The current method is not published +      PublicString SayHello2 (@WebParam (name= "name") String name); A}

2.Implement the interface

1 ImportJavax.jws.WebService;2 3 4 /**5 * WebService6 * Mark Java classes to implement Web service, or mark Java interfaces as defined Web service Interfaces7  */8@WebService (endpointinterface = "Com.mobile263.ISay")9  Public classSayimplImplementsIsay {Ten      One   A      Publicstring SayHello (string name) { -System.out.println ("SayHello got the Request:" +name);  -         return"Hello:" +name; the     } -      -     -      Publicstring Saygoodbye (string name) { +System.out.println ("Saygoodbye got the Request:" +name); -         return"Goodbye:" +name; +     } A      at     -      Publicstring SayHello2 (string name) { -         return"Hello" +name; -     } -  -  in}

3. Publish the WS in Server

1 ImportJavax.xml.ws.Endpoint;2 3 /**4 * WebService5 * Mark Java classes to implement Web service, or mark Java interfaces as defined Web service Interfaces6  */7 8  Public classWSServer {9 Ten      Public Static voidMain (string[] args) { One         /** A * Parameter 1: Publishing address of the service - * Parameter 2: The implementation of the service - * Endpoint will restart a thread the          */ -Endpoint.publish ("Http://localhost:8090/WStest/com.mobile.Wsserver",NewSayimpl ()); -System.out.println ("Server ready ..."); -     } +  -}

4. Input the link on Brouswer and enter,the WSDL would be shown. -HTTP://LOCALHOST:8090/WSTEST/COM.MOBILE.WSSERVER?WSDL

5. Use Wsimport to export the client files

Wsimport-d d:-keep-verbose http://localhost:8090/WStest/com.mobile.Wsserver?wsdl



WebService-use JAX-ws annotations to quickly build server and client

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.