Using JAX-WS to develop Web Service

Source: Internet
Author: User

Develop and access web service in myeclipse


1. Create a Web Service Project




Document directory:


2. Create a web service class.First, create a package named WebServices. Simple, and then create a class named calculator.


Add add, subtract, multiply, and divide methods to the calculator class.

package webservices.simple;public class Calculator {public int add(int a,int b){return (a + b);}public int subtract(int a,int b){return (a - b);}public int multiply(int a,int b){return (a * b);}public int divide(int a,int b){return (a / b);}}

3. Create a Web Service

The following is a Web Service generated based on the above class.





4. Deploy and test the Web Service


Both Tomcat and WebLogic have been tried and can be run. The following describes how to deploy and test weblogic.




Test the add method.



5. Create a web service client

First, create a project named webserviceclientproject. For the creation process, refer to the previous process. Create a package, WebServices. Simple. Client.

Next, create a web service client.




Note: If a verification error occurs, check whether the server is started and whether the Web Service is deployed.


Next, write the test class. Create a new class: webserviceclient, and select generate Mian method.


Package WebServices. simple. main; import WebServices. simple. client. calculatordelegate; import WebServices. simple. client. calculatorservice; public class webserviceclient {/*** @ Param ARGs */public static void main (string [] ARGs) {/* create a service instance */calculatorservice service = new calculatorservice (); calculatordelegate delegate = service. getcalculatorport ();/* call the web service and perform the addition, subtraction, multiplication, division operation */system. out. println ("1. 3 + 7 = "+ delegate. add (3, 7); system. out. println ("2. 12-2 = "+ delegate. subtract (12, 2); system. out. println ("3. 9*9 = "+ delegate. multiply (9, 9); system. out. println ("4. 40/2 = "+ delegate. divide (40, 2 ));}}

Running result:







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