Java WebService Simple Instance

Source: Internet
Author: User
Tags soap wsdl

Introduction: Before starting the following tutorials, 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

Vi. Examples of source code

Server Source Download

Client Source Download

    • Theservice.rar (5.6 KB)
    • Download number of times: 297
    • Theclient.rar (13.2 KB)
    • Download number of times: 240
    • View Picture Attachments
Disclaimer: Iteye article copyright belongs to the author, protected by law. No written permission of the author shall be reproduced. Recommended links
Back to Top
  • l396199657
  • Level: Junior Member
  • Gender:
  • Posts: 2
  • Reward Points: 30
  • From: Beijing
Release date: 2015-06-18 Last modified: 2015-06-18 service end in My computer to add the following Red Font section, no person reported com.sun.xml.internal.ws.model.RuntimeModelerException
Baidu to the following link address to find a solution
http://chenbingyyent.blog.163.com/blog/static/135278835201102484716262/


Package com.hyan.service;

Import Javax.jws.WebService;
Import Javax.xml.ws.Endpoint;
Import Javax.jws.WebService;
Import javax.jws.soap.SOAPBinding;
Import Javax.jws.soap.SOAPBinding.Style;


@WebService
@SOAPBinding (STYLE=STYLE.RPC)
public class Servicehello {
public string GetValue (string name) {
Return "My name is" +name+ ".";
}

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Endpoint.publish ("Http://localhost:9001/Service/ServiceHello", New Servicehello ());
SYSTEM.OUT.PRINTLN ("service success!");
}

}
Back to Top Reply Address 0 0 Please login and vote
  • Zlmwin
  • Level: Junior Member
  • Gender:
  • Posts: 1
  • Reward Points: 30
  • From: Beijing
Release date: 2015-07-01 if the path with spaces can be added "" causes a path with spaces example: Wsimport-s d:\\users\\workspaces\\ "MyEclipse 8.5" \\TheClient-p com.client- Keep Http://localhost:9001/service/ServiceHello

Java WebService Simple Instance

Related Article

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.