Java WebService Simple Instance

Source: Internet
Author: User

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 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



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 "generated 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

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

Vi. Examples of source code

Server Source Download

Client Source Download

Ext.: http://www.iteye.com/topic/1135747

Java WebService Simple Instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.