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: