读书人

MyEclipse6.5下基于JAX-WS开发Webserv

发布时间: 2012-10-24 14:15:58 作者: rapoo

MyEclipse6.5上基于JAX-WS开发Webservice(中文示例)

    package com.myeclipseide.ws; 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); } }
      <servlet> <description>JAX-WS endpoint - CalculatorService</description> <display-name>CalculatorService</display-name> <servlet-name>CalculatorService</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CalculatorService</servlet-name> <url-pattern>/CalculatorPort</url-pattern> </servlet-mapping>
        public static void main(String[] args) { /* Create the service instance */ CalculatorService service = new CalculatorService(); CalculatorDelegate delegate = service.getCalculatorPort(); /* Using the web service, perform the 4 calculations */ 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)); } 运行得到如下结果:
        1. 3+7=10
        2. 12-2=10
        3. 9*9=81
        4. 40/2=20
        测试完成。
        8. Resources
        In this section we want to provide you with additional links to resources that supplement the topics covered in this tutorial. While this is not an exhaustive list, we do make an effort to point to the more popular links that should provide you with diverse, high-quality information.

        Example Web Service Project & Web Service Client Project
        NOTE: The example projects provided are configured to run against WebSphere 6.1. You may need to adjust the Target Server and/or the runtime JRE libraries used to build the projects to more closely match your particular build and deployment environment.

读书人网 >Web前端

热点推荐