在 JAX-WS Web Service 中强制遵循 WSDL 绑定

Java™ API for XML-Based Web Services (JAX-WS) V2.1 引入了功能部件概念作为一种以程序方式控制特定功能和行为的方法。RespectBindingFeature 是其中一个支持的标准功能部件。可以使用 RespectBindingFeature 来控制 JAX-WS 实现是否必须遵循与端点相关联的 Web 服务描述语言 (WSDL) 绑定的内容。

关于此任务

虽然 WSDL 文档通常是在开发过程中使用,但是在提供 WSDL 文档规范时,JAX-WS 规范 V2.1 之前的版本中尚未明确定义在运行时关于此规范使用的实际施行。JAX-WS V2.1 规范添加了 RespectBindingFeature 功能部件以阐明 wsdl:binding 在 JAX-WS 运行时环境中的影响。

启用 RespectBindingFeature 功能部件会促使 JAX-WS 运行时环境在运行时检查端点的 wsdl:binding,以确保服务端点接口 (SEI) 参数和返回值的绑定得到遵循。此外,此功能部件还确保所有必需 wsdl:binding 扩展均为运行时环境所理解和使用,或者这些扩展已经为应用程序所显式禁用。JAX-WS 应用程序可以使用与 WebServiceFeature 功能部件相关联的相应注释,使用可接受 javax.xml.ws.WebServiceFeature 接口的 API,或者配置部署描述符,以禁用具有已定义 WebServiceFeature 接口的特定 wsdl:binding 扩展。

如果 RespectBindingFeature 功能部件未启用(缺省值),那么运行时环境可以选择是否施行 wsdl:binding 的任何部分。

过程

  1. 为包含 Web 服务描述语言 (WSDL) 文件(用于表示 Web Service 应用程序)的 JAX-WS 应用程序开发 Java 工件。
    1. 如果要从 WSDL 文件开始,那么通过使用 wsimport 命令来生成必需的 JAX-WS 可移植工件,从 WSDL 文件开发 Java 工件
    2. 如果要从 JavaBeans 组件开始,那么为 JAX-WS 应用程序开发 Java 工件以及使用 wsgen 命令来生成 WSDL 文件。
  2. 如果要对端点实现类启用 RespectBindingFeature,请使用下列其中一种方法:
    • 在端点上使用 @RespectBinding 注释。

      要对端点启用 RespectBinding,请在端点上使用 @RespectBinding (javax.xml.ws.RespectBinding) 注释。@RespectBinding 注释只有一个参数 enabled。此参数是可选的。enabled 参数具有布尔值并表示是否为 JAX-WS 端点启用 RespectBindingFeature。

      以下示例片段说明如何为 JAX-WS MyServiceImpl 端点添加 @RespectBinding 注释:
      @RespectBinding(enabled=true))
      @WebService
      public class MyServiceImpl {
      ...
      }
    • 使用 <respect-binding> 部署描述符元素。
      可以在 webservices.xml 部署描述符的 <port-component> 元素中使用 <respect-binding> 元素,作为在服务端点实现类上使用 @RespectBinding 注释的替代选择;例如:
      <port-component>
           <port-component-name>MyPort1</port-component-name>
           <respect-binding>
               <enabled>true</enabled>
           </respect-binding>
           <service-impl-bean>
               <servlet-link>MyPort1ImplBean</servlet-link>
           </service-impl-bean>
      </port-component>
  3. 如果要对客户机启用 RespectBindingFeature,请使用下列其中一种方法:
    • 对 Dispatch client 启用 RespectBindingFeature;例如:
      RespectBindingFeature respectBinding = new RespectBindingFeature();
      Service svc = Service.create(serviceName);
      svc.addPort(portName, SOAPBinding.SOAP11_HTTP_BINDING, endpointUrl);
      Dispatch<Source> dsp = svc.createDispatch(portName, Source.class, Service.Mode.PAYLOAD, respectBinding);
    • 对动态代理客户机启用 RespectBindingFeature;例如:
      // Create a dynamic proxy with RespectBinding enabled.
        Service svc = Service.create(serviceName);
        RespectBindingFeature respectBinding = new RespectBindingFeature();
        RespectBindingSample proxy = svc.getPort(portName, RespectBindingSample.class, respectBinding);
    • 使用 @RespectBinding 注释来对客户机启用 RespectBindingFeature;例如:
      public class MyClientApplication {
      
                     // Enable RespectBinding for a port-component-ref resource injection.
                         @RespectBinding(enabled=true)
                         @WebServiceRef(MyService.class)
                         private MyPortType myPort;
                     ...
      }
    • 在 port-component-ref 元素中使用部署描述符元素来对客户机启用 RespectBindingFeature;例如:
      <service-ref>
          <service-ref-name>service/MyPortComponentRef</service-ref-name>
          <service-interface>com.example.MyService</service-ref-interface>
          <port-component-ref>
              <service-endpoint-interface>com.example.MyPortType</service-endpoint-interface>
              <respect-binding>
                  <enabled>true</enabled>
              </respect-binding>
          </port-component-ref>
      </service-ref>

结果

通过实现 RespectBindingFeature 功能部件,您已指定强制遵循与 JAX-WS 应用程序的端点相关联的 WSDL 绑定内容。


指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_enablerespectbindingfeature
文件名:twbs_enablerespectbindingfeature.html