Preface: Before starting the following tutorial, please look at the fifth precautions to avoid unnecessary repetitions.
1. Preparation work (the following are the tools used in this example)
1. MyEclipse10.7.1
2. JDK 1.6.0_22
2. Create a server
1. Create [Web Service Project] and name it [TheService].
2. Create a [Class] class, named [ServiceHello], located in the [com.hyan.service] package.
3. Write methods for client calls, that is, compile method code.
4. Compile
Note: If the compilation fails, please set the jdk referenced by this project to version 1.6.0_17 or higher
5. Test results
Test address: http://localhost:9001/Service/ServiceHello?wsdl
3. Generate client
1. Create [Web Service Project] and name it [TheClient].
2. The command prompt window executes the generated command.
Format: wsimport -s "src directory" -p "package name where the generated class is located" -keep "wsdl publishing address"
Example:
The code copy is as follows:
wsimport -s G://workspace//webService//TheClient//src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello?wsdl
illustrate:
1) The address of "src directory" must not contain spaces
2) Don’t miss “wsdl publishing address”?wsdl”
3. Refresh the project and check the generated class
4. Final test
1. Create a [Class] class, named [ServiceTest], located in the [com.hyan.test] package.
2. Write a test method, call the server method, and print the returned result.
5. Things to note
1. The problem of JDK version being too low
Report an exception similar to the following: runtime modeler error: Wrapper class com.hyan.service.jaxws.GetValue is not found. Have you run APT to generate them?
Reason: JDK version is lower than 1.6.0_17
Solution: Adjust the JDK version referenced by this server project to the installed higher version of JDK
2. Problem of generating command path with spaces
Report an exception similar to the following: directory not found: G:/SVN_FILE/GB/05
Reason: The client src path cannot contain spaces
Solution: Just recreate the client in a folder without space paths.
3. The problem of incomplete generation of commands
An exception similar to the following: [ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):
Cause: "?wsdl" is missing at the end of the generated command
Solution: Just make up.
Example of incomplete commands for errors:
wsimport -s G://workspace//webService//TheClient//src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello
Correct and complete command example:
wsimport -s G://workspace//webService//TheClient//src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello?wsdl
VI. Sample source code
Server source code download
Client source code download
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.