Using eclipse to develop the first WebService program, the tool for this example is spring-tool-suite, and there is no essential difference between eclipse and the development environment jdk1.7
first, the development steps:
1. Create a new project named WebService
New HelloService class, placed under the Com.test.webservice package
The following is the preparation of the service-side program:
1 PackageCom.test.webservice;2 ImportJavax.jws.WebService;3 ImportJavax.xml.ws.Endpoint;4 //Add WebService Annotations, note that the name of the package should not be quoted incorrectly.5 @WebService6 Public classHelloService {7 /**8 * The method has a common client call, which returns a string9 * @paramnameTen * @return One * @returnString A */ - Publicstring GetValue (string name) { - return"Hello" +name; the } - /** - * The Main method is used to publish the server to localhost locally, the second parameter is the local object created - * @paramargs + * @returnvoid - */ + Public Static voidMain (string[] args) { AEndpoint.publish ("Http://localhost:1008/service/serviceHello",NewHelloService ()); atSystem.out.println ("published successfully!")); - } -}
Run, compile the class, and the result is as follows:
Browser input: HTTP://LOCALHOST:1008/SERVICE/SERVICEHELLO?WSDL, you can see the information, the compilation is successful!
2. Next build the client
2.1 The Build client program can create a new WebService project, or create a new package based on the original project, in order to facilitate the use of the second method: Create a new package named client
2.2 Open a command prompt window to execute the build command.
format:wsimport-s "src directory"-P "generate class with package name"-keep "WSDL publishing Address"
Example:
C:\users\wangsj>wsimport-s e:\\workingfoilder\\projectspace\\webservice\\src-p Com.test.webservice.client- Keep HTTP://LOCALHOST:1008/SERVICE/SERVICEHELLO?WSDL
Description
1) "src directory" address cannot contain spaces
2) "WSDL publishing address" Don't miss "? wsdl"
No error, instructions compiled successfully! Refresh the project to see the class that generated the client response:
3, new test class, for testing
1 Packagecom.test.webservice.test;2 //Note that the package name cannot be quoted incorrectly.3 ImportCom.test.webservice.client.HelloService;4 ImportCom.test.webservice.client.HelloServiceService;5 Public classTest {6 7 Public Static voidMain (string[] args) {8 //initialize the object and get the port9HelloService sh=NewHelloserviceservice (). Gethelloserviceport ();Ten //invoking a service-side method OneString name=sh.getvalue ("WebService"); A System.out.println (name); - } - the}
Run can see the results of the run and prove that the first WebService program was created successfully!
Iv. Summary
1. If an exception occurs during operation, for example: Runtime Modeler Error:wrapper class Com.hyan.service.jaxws.GetValue is not found. You run an APT to generate them?, stating that the current JDK version is too low, it is recommended to upgrade to version 1.7 and try again.
2, if the path is wrong, or the path contains a space, you will report the error, I write the wrong time, so write the path must be serious
3, the end of the WSDL must not be lost.
WebService applications-using Java to develop WebService programs