Yesterday, I sorted out the basic concepts related to Web services. As a result of that blog, this article will explain how to write WebService server programs and how to call self-compiled services.
Step 1, create a WebService project, select the JAX-WS [Note: this example uses IDE for myeclipse]
Step 2: create a service class
Package COM. xjtu. webService;/***** <p> * Title: Test code/P> *** <p> * description: example business class * </P> ** <p> * copyright: Copyright (c) 2012 * </P> ** @ author DML @ 2012-12-11 * @ version 1.0 */public class mobilenuminfo {Public String getmobilenum () {return "13888888888 ";}}
Step 3: Release the web service. Select the project you just created, and choose create Web service from Java class from strategy.
Step 4: generate the WSDL
Step 5, add the library file [JAX-WS *]
Step 6: start Tomcat
Step 7: Open your browser and enter the address http: // 127.0.0.1: 8080/mobilenumservice/mobilenuminfoport? WSDL
The following page is displayed, indicating that the service has been released successfully.
Step 8: Create a client test project and select Java project.
Step 9: generate the library file required by WS
Generate files such:
Step 10: Compile the test program and view the execution result
Package COM. xjtu. webService. test; import COM. xjtu. webService. mobilenuminfodelegate; import COM. xjtu. webService. mobilenuminfoservice;/***** <p> * Title: Test code/P> ** <p> * description: example business class * </P> ** <p> * copyright: Copyright (c) 2012 * </P> ** @ author DML @ 2012-12-11 * @ version 1.0 */public class mobilenumtest {public static void main (string [] ARGs) {mobilenuminfoservice mnis = new mobilenuminfoservice (); mobilenuminfodelegate mnid = mnis. getmobilenuminfoport (); system. out. println (mnid. getmobilenum ());}}
Execution result:
13888888888
Next, you can refer to the source code for detailed explanation of Java WebService program.
P.s. The process is actually not difficult, and you can master it by yourself.
Pp. S. The temperature drops sharply. You should pay more attention to adding clothes to keep warm ~~ As long as you do not get sick, it is happiness.
PPP. s. in this world, "the only thing that is unstoppable is time. It is like a blade, silently cutting everything hard and soft and moving forward steadily, nothing can make its progress bumpy, but it changes everything."
Dml@2012.12.11