Java WebService simple instance, javawebservice
Before starting the following tutorial, let's take a look at the things you should pay attention to in order to avoid unnecessary repeated operations.
I. Preparations (the following are the tools used for this instance)
1. MyEclipse10.7.1
2. JDK 1.6.0 _ 22
2. Create a server
1. Create a Web Service Project named TheService ].
2. Create a [Class] Class named [ServiceHello], which is located under the [com. hyan. service] package.
3. Compile the method code called by the client.
4. Compile
Note:If compilation fails, set the jdk referenced by this project to version 1.6.0 _ 17 or later.
5. Test Results
Test address:Http: // localhost: 9001/Service/ServiceHello? Wsdl
3. Generate a client
1. Create a Web Service Project named TheClient ].
2. Run the generate command in the Command Prompt window.
Format:Wsimport-s "src directory"-p "generate class 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
Note:
1) The "src directory" address cannot contain spaces
2) do not miss "? Wsdl"
3. Refresh the project and check the generated class.
Iv. Final Test
1. Create a [Class] Class named [ServiceTest], which is located in the [com. hyan. test] package.
2. Compile the test method, call the server method, and print the returned results.
5. Notes
1. JDK version is too low
An exception similar to the following is reported:Runtime modeler error: Wrapper class com. hyan. service. jaxws. GetValue is not found. Have you run APT to generate them?
Cause:JDK version earlier than 1.6.0 _ 17
Solution:Adjust the JDK version referenced by this server project to a later JDK version.
2. Generate command paths with spaces
An exception similar to the following is reported:Directory not found: G: \ SVN_FILE \ GB \ 05
Cause:The client src path cannot contain spaces
Solution:Create a new client in a folder without spaces.
3. Incomplete command generation
An exception similar to the following is reported:[ERROR] failed. noservice = cocould not find wsdl: service in the provided WSDL (s ):
Cause:"?" Is missing at the end of the generated command. Wsdl"
Solution:Complete the configuration.
Command example with incomplete 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
Download Server Source Code
Download client source code