Preface: Before starting the following tutorial, please look at the fifth big point to avoid unnecessary duplication of operations.
First, the preparation work (the following is the use of the tool for this example)
1, MyEclipse10.7.1
2. JDK 1.6.0_22
Second, create the service side
1. Create "Web Service Project", named "Theservice".
2. Create the "class" class, named "Servicehello", located under the "Com.hyan.service" package.
3, write the method for the client to call, that is, compile the method code.
4, to compile
Description: If the compilation fails, set the JDK referenced by the project to 1.6.0_17 version or later
5. Test results
Test Address:http://localhost:9001/Service/ServiceHello?wsdl
Third, generate the client
1. Create "Web Service Project", named "Theclient".
2. The command Prompt window executes the build command.
format:wsimport-s "src directory"-P "generate class with package name"-keep "WSDL publishing Address"
Example:
Wsimport-s g:\\workspace\\webservice\\theclient\\src-p Com.hyan.client-keep http://localhost:9001/Service/ servicehello?wsdl
Description
1) "src directory" address cannot contain spaces
2) "WSDL publishing address" Don't miss "? wsdl"
3, refresh the project, check the generated class
Iv. final Test
1. Create the "class" class, named "Servicetest", located under the "Com.hyan.test" package.
2, write the test method, call the service-side method, and print the returned results.
Five, matters needing attention
1, JDK version too low problem
the report resembles the following exception:Runtime Modeler Error:wrapper class Com.hyan.service.jaxws.GetValue is not found. Do you run the APT to generate them?
Reason: JDK version less than 1.6.0_17
Workaround: Adjust the JDK version referenced by this server-side project as a high-build JDK installed
2. Generate command path with whitespace issues
the report resembles the following exception:directory not found:g:\svn_file\gb\05
Cause: The client src path must not contain spaces
Workaround: recreate the client under a folder that does not contain a space path.
3. Incomplete command generation
report 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 build command
Workaround: fill up.
An example of an incomplete error command:
Wsimport-s g:\\workspace\\webservice\\theclient\\src-p Com.hyan.client-keep Http://localhost:9001/Service/ServiceHello
Examples of correct and complete commands:
Wsimport-s g:\\workspace\\webservice\\theclient\\src-p Com.hyan.client-keep http://localhost:9001/Service/ servicehello?wsdl
Server Source Download
Client Source Download
Java WebService Simple Instance