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