Simple instance of Java WebService.

Preparations (the following tools are used for this example)

1、MyEclipse10.7.1

2、JDK 1.6.0_22

Create a server

1. Create a [Web Service Project] and name it [TheService].



 

 

 

2. Create a [Class] class, named [ServiceHello], under the [com.hyan.service] package.



 

 

 

3. Write a method for the client to call, that is, compile the method code.



 

 

4. Compile

Note: If the compilation fails, please set the jdk referenced by the project to version 1.6.0_17 or higher



 

 

 

5. Test results

Test address: http://localhost:9001/Service/ServiceHello?wsdl



generate client

1. Create [Web Service Project] and name it [TheClient].



 

 

 

 

2. The command prompt window executes the build command.

Format: wsimport -s "src directory" -p "package name where the generated class is located" -keep "wsdl release address"

Example:

wsimport -s G:\\workspace\\webService\\TheClient\\src -p com.hyan.client -keep http://localhost:9001/Service/ServiceHello?wsdl

illustrate:

1) The "src directory" address cannot contain spaces

2) Do not miss "?wsdl" in "wsdl release address"



 

 

3. Refresh the project and check the generated class



 

 

final test

1. Create a [Class] class, named [ServiceTest], under the [com.hyan.test] package.





  

 

 

2. Write a test method, call the server method, and print the returned result.



 

 

 Precautions

1. The 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?



 

Reason: JDK version is lower than 1.6.0_17

Solution: Adjust the JDK version referenced by the server project to the installed higher version JDK



 

 

 

 

 

 

 

 

 

 

 

 

2. The generated command path contains spaces

An exception similar to the following is reported: directory not found: G:\SVN_FILE\GB\05



 

Reason: The client src path cannot contain spaces

Workaround: Just recreate the client in a folder with no spaces in the path.

 

3. Incomplete build command

An exception similar to the following is reported: [ERROR] failed.noservice=Could not find wsdl:service in the provided WSDL(s):



 

Cause: Missing '?wsdl' at the end of the build command

Solution: Just add it.

Example of an incorrectly incomplete command:

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


Reprinted: http://www.cnblogs.com/yisheng163/p/4524808.html?utm_source=tuicool

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324692964&siteId=291194637