zoukankan      html  css  js  c++  java
  • JAX-WS注解

    1.1      JAX-WS注解

    1.1.1     注解说明

    WebService的注解都位于javax.jws包下:

    @WebService-定义服务,在public class上边

    targetNamespace:指定命名空间

    name:portType的名称

    portName:port的名称

    serviceName:服务名称

    endpointInterface:SEI接口地址,如果一个服务类实现了多个接口,只需要发布一个接口的方法,可通过此注解指定要发布服务的接口。

    @WebMethod-定义方法,在公开方法上边

           operationName:方法名

           exclude:设置为true表示此方法不是webservice方法,反之则表示webservice方法

    @WebResult-定义返回值,在方法返回值前边

           name:返回结果值的名称

    @WebParam-定义参数,在方法参数前边

           name:指定参数的名称

    作用:

    通过注解,可以更加形像的描述Web服务。对自动生成的wsdl文档进行修改,为使用者提供一个更加清晰的wsdl文档。

    当修改了WebService注解之后,会影响客户端生成的代码。调用的方法名和参数名也发生了变化

    1.1.2     注解示例:

    /**

     * 天气查询服务接口实现类

     * @version V1.0

     */

    @WebService(targetNamespace="http:// webservice.itcast.cn",

    serviceName="weatherService",

    portName="weatherServicePort",

    name="weatherServiceInterface"

    )

    public class WeatherInterfaceImpl implements WeatherInterface {

       

        @WebMethod(operationName="queryWeather")

        public @WebResult(name="weatherResult")String queryWeather(

               @WebParam(name="cityName")String cityName) {

           System.out.println("from client.."+cityName);

           String result = "晴朗";

           System.out.println("to client..."+result);

           return result;

        }

       

        public static void main(String[] args) {

           //发送webservice服务

           Endpoint.publish("http://192.168.1.100:1234/weather", new WeatherInterfaceImpl());

        }

       

    }

     

    1.1.3     使用注解注意

    @WebMethod对所有非静态的公共方法对外暴露为服务.

    对于静态方法或非public方法是不可以使用@WebMethod注解的.

    对public方法可以使用@WebMethod(exclude=true)定义为非对外暴露的服务。

  • 相关阅读:
    微博个人中心效果
    微博弹性按钮
    ios9 3dtouch 博客
    去掉导航栏阴影
    模态全屏模式,实现半透明效果
    剪切图片
    修改push动画的方向
    数据库链接池终于搞对了,直接从100ms到3ms
    如何在Java代码中去掉烦人的“!=null”
    面试官:请讲下接口具体怎么优化!
  • 原文地址:https://www.cnblogs.com/webyyq/p/8642016.html
Copyright © 2011-2022 走看看