JAX-WS WebService、寻址、MTOM 和 RespectBinding 功能用例

JAX-WS WebService, Addressing, MTOM and RespectBinding Features Use Cases

我正在 Java 学习 Web 服务。我想借助一个非常简单的用例了解以下 4 类 的用途 - WebServiceFeature、AddressingFeature、MTOMFeature、RespectBindingFeature。

假设,我正在发布一个将列出美国所有州的 Web 服务。我将如何利用这 4 类?

Java API for XML-Based Web Services (JAX-WS) 版本 2.1 引入了功能的概念,作为一种以编程方式控制特定功能和行为的方式。

WebServiceFeature 根据 Java Doc

A WebServiceFeature is used to represent a feature that can be enabled or disabled for a web service.

The JAX-WS specification will define some standard features and JAX-WS implementors are free to define additional features if necessary. Vendor specific features may not be portable so caution should be used when using them.

AddressingFeature 根据 Java Doc

AddressingFeature represents the use of WS-Addressing with either the SOAP 1.1/HTTP or SOAP 1.2/HTTP binding. Using this feature with any other binding is undefined.

This feature can be used during the creation of SEI proxy, and Dispatch instances on the client side and Endpoint instances on the server side. This feature cannot be used for Service instance creation on the client side.

MTOMFeature 根据 Java Doc

This feature represents the use of MTOM with a web service.

还有

JAX-WS supports the use of SOAP Message Transmission Optimized Mechanism (MTOM) for sending binary attachment data. By enabling MTOM, you can send and receive binary data optimally without incurring the cost of data encoding needed to embed the binary data in an XML document.

RespectBindingFeature 根据 Java Doc

This feature clarifies the use of the wsdl:binding in a JAX-WS runtime. This feature can be used during the creation of SEI proxy, and Dispatch instances on the client side and Endpoint instances on the server side. This feature cannot be used for Service instance creation on the client side.

This feature is only useful with web services that have an associated WSDL.

用例 - 不幸的是,请参阅 Java 文档 - 我只是说不幸的是,我已经开发 Web 服务好几年了 - 我从来不需要使用 "WebServiceFeature,AddressingFeature, MTOMFeature, RespectBindingFeature" - 它们适用于我认为大多数开发人员不需要处理的利基用例。我看到的最有用的是 MTOMFeature,但如果您只是想要一个列出所有美国的 Web 服务 - 您可能不需要任何详细说明的东西。

一些用例发现

MTOM: Using JAX-WS, you can send binary attachments such as images or files along with web services requests. With your example of States - you could have a web service that request that sets/updates each a picture of the states state bird and a base64 encoded audio file of the state song - the picture and song could be MTOM attachments.

AddressingFeature: This looks like it's just used when either the web service or web service client need to use WS-Addressing. I'd imagine trying to integrate with a third party web service that requires the use of WS-Addressing in which case your client you write would need to specify it's use

RespectBindingFeature: You can use the RespectBindingFeature to control whether a JAX-WS implementation is required to respect the contents of a Web Services Description Language (WSDL) binding that is associated with an endpoint. By implementing the feature, RespectBindingFeature, you have specified to enforce adherence of the contents of a WSDL binding that is associated with an endpoint for your JAX-WS application. The actual enforcement of the use of the WSDL document specifications, when they are provided, at run time has not been well defined in versions of the JAX-WS specification previous to Version 2.1.

WebServiceFeature: this is the parent class for the other features. The use case I imagine would only be the facts that the sub-classes inherit from it.