One, server-side
1. Create a Web project with the project name Ws_server
2. Create the package and create the Testservice class under the package:
Package Com.test.webservice; Public class Testservice { publicstaticfinal String TITLE = "This message is returned by the WebService server side:"; Public string Test (String msg) { return TITLE + msg;} }
3, the Testservice.java class into the server side:
(1) Class name-right-click-web service-web Service
(2) Click Next
(3) Click Next, select the class that you want to be the server side, and then click the Finish button when you are finished.
(4) can be found under the package more than one Testservicedelegate.java class; Web-inf a sun-jaxws.xml file.
(5) Add the jar package and allow Tomcat. When you're done, type: HTTP://LOCALHOST:8080/WS_SERVER/TESTSERVICEPORT?WSDL in the browser's address bar, and the results are as follows:
Second, the client
(1) Create a Web project with the project name: ws_client
(2) Create a new Web Service client, such as the server side, you can use the following shortcut button
(3) Enter the server-side WSDL address: Click Next and the client's file will be generated.
(4) Create Testclient.java
Package Com.test.webservice; Public class testclient { publicstaticvoid main (string[] args) { new Testserviceservice (). Gettestserviceport (); // call the server-side test method SYSTEM.OUT.PRINTLN ("------&&&&& Witness Results &&&&&&------"); SYSTEM.OUT.PRINTLN (result);} }
(5) Add the project to Tomcat, start the server, and execute the client's testclient with the following results:
Using Jax-rs for Web service Interface development