MyEclipse Development WebService Tutorial

Source: Internet
Author: User

http://blog.csdn.net/flightme/article/details/6977191

. Create a WebService project.

2. Create a plain Java Class View plaincopy to Clipboard
  1. Package com.hmw.jaxws;
  2. /**
  3. * Test <br> for WebService service
  4. * <b> Note:</b> The class must have a parameterless construction method, or you cannot use the MyEclipse Wizard to create a JAX-WS WebService Server class for this class <br>
  5. * <b> Created Date </b>:2011-1-17
  6. * @author <a href= "Mailto:[email protected]" mce_href= "Mailto:[email protected]" > He Mingwang </a>
  7. */
  8. Public class Hellojaxws {
  9. public string SayHello (string userName) {
  10. return userName + "Hello, this is my first JAX-ws program. ";
  11. }
  12. public int Add (int i, int j) {
  13. return i + j;
  14. }
  15. }
[Java]View Plaincopy
  1. Package com.hmw.jaxws;
  2. /**
  3. * Test <br> for WebService service
  4. * <b> Note:</b> The class must have a parameterless construction method, or you cannot use the MyEclipse Wizard to create a JAX-WS WebService Server class for this class <br>
  5. * <b> Created Date </b>:2011-1-17
  6. * @author <a href= "Mailto:[email protected]" mce_href= "Mailto:[email protected]" > He Mingwang </a>
  7. */
  8. Public class Hellojaxws {
  9. Public string SayHello (String userName) {
  10. return userName + "Hello, this is my first JAX-ws program.    ";
  11. }
  12. public int Add (int i, int j) {
  13. return i + j;
  14. }
  15. }

3. Create a WebService server

The source code for Hellojaxwsdelegate.java is as follows:

View Plaincopy to Clipboard
  1. Package com.hmw.jaxws;
  2. @javax. Jws.webservice (targetnamespace = "http://jaxws.hmw.com/", ServiceName ="Hellojaxwsservice", PortName = "Hellojaxwsport", wsdllocation = "web-inf/wsdl/hellojaxwsservice.wsdl")
  3. Public class Hellojaxwsdelegate {
  4. Com.hmw.jaxws.HelloJaxws Hellojaxws = new Com.hmw.jaxws.HelloJaxws ();
  5. public string SayHello (string userName) {
  6. Return Hellojaxws.sayhello (UserName);
  7. }
  8. public int Add (int i, int j) {
  9. Return Hellojaxws.add (i, j);
  10. }
  11. }
[Java]View Plaincopy
  1. Package com.hmw.jaxws;
  2. @javax. Jws.webservice (targetnamespace = "http://jaxws.hmw.com/", ServiceName = "Hellojaxwsservice", PortName = "Hellojaxwsport", wsdllocation = "web-inf/wsdl/hellojaxwsservice.wsdl")
  3. Public class Hellojaxwsdelegate {
  4. Com.hmw.jaxws.HelloJaxws Hellojaxws = new Com.hmw.jaxws.HelloJaxws ();
  5. Public string SayHello (String userName) {
  6. return Hellojaxws.sayhello (userName);
  7. }
  8. public int Add (int i, int j) {
  9. return Hellojaxws.add (i, j);
  10. }
  11. }
4. Import the associated jar package and send the project to Tomcat to launch Tomcat.

The directory structure for the entire project is as follows:

5. Create a WebService client project (plain Java project).

6. Create a client-related call class

7. Create a test class

The code for the test class Clienttest.java is as follows:

View Plaincopy to Clipboard
    1. Package com.hmw.client.jaxws;
    2. Public class Clienttest {
    3. Public static void Main (string[] args) {
    4. Hellojaxwsdelegate service = new Hellojaxwsservice (). Gethellojaxwsport ();
    5. System.out.println (Service.sayhello ("Hemingwang"));
    6. System.out.println ("result is:" + service.add (1, 2));
    7. }
    8. }
[Java]View Plaincopy
  1. Package com.hmw.client.jaxws;
  2. Public class Clienttest {
  3. public static void Main (string[] args) {
  4. Hellojaxwsdelegate service = new Hellojaxwsservice (). Gethellojaxwsport ();
  5. System.out.println (Service.sayhello ("Hemingwang"));
  6. System.out.println ("result is:" + service.add (1, 2));
  7. }
  8. }

The directory structure for the entire project is as follows:

8. Run the test class

The results of the operation are as follows:

MyEclipse Development WebService Tutorial (GO)

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.