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)定义为非对外暴露的服务。

转载于:https://www.cnblogs.com/webyyq/p/8642016.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值