Document 风格和 RPC 风格的通信有什么区别? [英] What is the difference between Document style and RPC style communication?

查看:35
本文介绍了Document 风格和 RPC 风格的通信有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释文档和 RPC 风格的网络服务之间的区别吗?除了 JAX-RPC,下一个版本是 JAX-WS,它同时支持 Document 和 RPC 样式.我也了解文档样式的 Web 服务适用于异步通信,其中客户端在收到响应之前不会阻塞.

Can somebody explain to me the differences between Document and RPC style webservices? Apart from JAX-RPC, the next version is JAX-WS, which supports both Document and RPC styles. I also understand document style webservices are meant for Asynchronous communication where a client would not block until the response is received.

无论哪种方式,我目前都使用 JAX-WS 使用 @Webservice 对服务进行注释,生成 WSDL,然后从该 WSDL 生成客户端工件.

Either way, using JAX-WS I currently annotate the service with @Webservice, generate the WSDL and from that WSDL I generate the client side artifacts.

收到工件后,在两种样式中,我都会调用端口上的方法.现在,这在 RPC 样式和文档样式中没有区别.那么区别是什么?区别在哪里?

Once the artifacts are received, in both styles, I invoke the method on the port. Now, this does not differ in RPC style and Document style. So what is the difference and where is that difference visible?

同样,SOAP over HTTP 与 XML over HTTP 有何不同?毕竟 SOAP 也是带有 SOAP 命名空间的 XML 文档.

Similarly, in what way does SOAP over HTTP differ from XML over HTTP? After all SOAP is also XML document with SOAP namespace.

推荐答案

有人可以解释一下文档样式和文档样式之间的区别吗?RPC 风格的网络服务?

Can some body explain me the differences between a Document style and RPC style webservices?

有两种通信样式模型可用于将 WSDL 绑定转换为 SOAP 消息体.他们是:文档&RPC

There are two communication style models that are used to translate a WSDL binding to a SOAP message body. They are: Document & RPC

使用文档样式模型的优点是,只要 SOAP 消息体的内容是任意的 XML 实例,您就可以按照您想要的任何方式构造 SOAP 体.文档样式也称为面向消息的样式.

The advantage of using a Document style model is that you can structure the SOAP body any way you want it as long as the content of the SOAP message body is any arbitrary XML instance. The Document style is also referred to as Message-Oriented style.

但是,对于RPC 样式模型,SOAP 请求主体的结构必须同时包含操作名称和方法参数集.RPC 样式模型假定消息正文中包含的 XML 实例 具有特定结构.

However, with an RPC style model, the structure of the SOAP request body must contain both the operation name and the set of method parameters. The RPC style model assumes a specific structure to the XML instance contained in the message body.

此外,有两种编码使用模型用于将 WSDL 绑定转换为 SOAP 消息.它们是:文字和编码

Furthermore, there are two encoding use models that are used to translate a WSDL binding to a SOAP message. They are: literal, and encoded

使用字面使用模型时,正文内容应符合用户定义的XML-schema(XSD) 结构.优点是双重的.一方面,您可以使用用户定义的 XML 模式验证消息正文,此外,您还可以使用 XSLT 等转换语言来转换消息.

When using a literal use model, the body contents should conform to a user-defined XML-schema(XSD) structure. The advantage is two-fold. For one, you can validate the message body with the user-defined XML-schema, moreover, you can also transform the message using a transformation language like XSLT.

使用 (SOAP) 编码使用模型,消息必须使用 XSD 数据类型,但消息的结构不需要符合任何用户定义的 XML 模式.这使得验证消息正文或在消息正文上使用基于 XSLT 的转换变得困难.

With a (SOAP) encoded use model, the message has to use XSD datatypes, but the structure of the message need not conform to any user-defined XML schema. This makes it difficult to validate the message body or use XSLT based transformations on the message body.

不同风格和使用模型的组合为我们提供了四种不同的方法来将 WSDL 绑定转换为 SOAP 消息.

The combination of the different style and use models give us four different ways to translate a WSDL binding to a SOAP message.

Document/literal
Document/encoded
RPC/literal
RPC/encoded

我建议您阅读这篇题为 哪种风格的文章我应该使用 WSDL? 作者 Russell Butek,他很好地讨论了将 WSDL 绑定转换为 SOAP 消息的不同风格和使用模型,以及它们的相对优势和劣势.

I would recommend that you read this article entitled Which style of WSDL should I use? by Russell Butek which has a nice discussion of the different style and use models to translate a WSDL binding to a SOAP message, and their relative strengths and weaknesses.

收到工件后,在两种交流方式中,我调用端口上的方法.现在,这在 RPC 风格上没有区别和文档样式.那么有什么区别,那在哪里差异可见?

Once the artifacts are received, in both styles of communication, I invoke the method on the port. Now, this does not differ in RPC style and Document style. So what is the difference and where is that difference visible?

你能找到差异的地方是RESPONSE"!

The place where you can find the difference is the "RESPONSE"!

RPC 样式:

package com.sample;
 
import java.util.ArrayList;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style=Style.RPC)
public interface StockPrice { 

    public String getStockPrice(String stockName); 

    public ArrayList getStockPriceList(ArrayList stockNameList); 
}

第二个操作的 SOAP 消息将有空输出,看起来像:

The SOAP message for second operation will have empty output and will look like:

RPC 样式响应:

<ns2:getStockPriceListResponse 
       xmlns:ns2="http://sample.com/">
    <return/>
</ns2:getStockPriceListResponse>
</S:Body>
</S:Envelope>

文档样式:

package com.sample;
 
import java.util.ArrayList;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
 
@WebService
@SOAPBinding(style=Style.DOCUMENT)
public interface StockPrice {
 
    public String getStockPrice(String stockName);
 
    public ArrayList getStockPriceList(ArrayList stockNameList);
}

如果我们为上述 SEI 运行客户端,输出为:

If we run the client for the above SEI, the output is:

123[123, 456]

123 [123, 456]

此输出显示 ArrayList 元素正在 Web 服务和客户端之间进行交换.此更改仅通过更改 SOAPBinding 注释的样式属性来完成.数据类型更丰富的第二种方法的 SOAP 消息如下所示,以供参考:

This output shows that ArrayList elements are getting exchanged between the web service and client. This change has been done only by the changing the style attribute of SOAPBinding annotation. The SOAP message for the second method with richer data type is shown below for reference:

文档样式响应:

<ns2:getStockPriceListResponse 
       xmlns:ns2="http://sample.com/">
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xsi:type="xs:string">123</return>
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xsi:type="xs:string">456</return>
</ns2:getStockPriceListResponse>
</S:Body>
</S:Envelope>

结论

  • 正如您在两个 SOAP 响应消息中所注意到的那样,可以在 DOCUMENT 样式的情况下验证 SOAP 响应消息,但不能在 RPC 样式的 Web 服务中进行验证.
  • 基本的使用 RPC 风格的缺点是它不支持更丰富的数据类型,并且使用 Document 样式XSD 的形式带来了一些复杂性,用于定义更丰富的数据类型.
  • 选择使用其中之一取决于操作/方法要求和预期客户.
  • As you would have noticed in the two SOAP response messages that it is possible to validate the SOAP response message in case of DOCUMENT style but not in RPC style web services.
  • The basic disadvantage of using RPC style is that it doesn’t support richer data types and that of using Document style is that it brings some complexity in the form of XSD for defining the richer data types.
  • The choice of using one out of these depends upon the operation/method requirements and the expected clients.

同样,SOAP over HTTP 与 XML over HTTP 有何不同?后所有 SOAP 也是具有 SOAP 命名空间的 XML 文档.那么什么是这里的区别?

Similarly, in what way SOAP over HTTP differ from XML over HTTP? After all SOAP is also XML document with SOAP namespace. So what is the difference here?

为什么我们需要像 SOAP 这样的标准?通过通过 HTTP 交换 XML 文档,两个程序可以交换丰富的结构化信息,而无需引入额外的标准(如 SOAP)来明确描述消息信封格式和对结构化内容进行编码的方法.

Why do we need a standard like SOAP? By exchanging XML documents over HTTP, two programs can exchange rich, structured information without the introduction of an additional standard such as SOAP to explicitly describe a message envelope format and a way to encode structured content.

SOAP 提供了一个标准,因此开发人员不必为他们想要提供的每项服务发明自定义 XML 消息格式.给定要调用的服务方法的签名,SOAP 规范规定了一种明确的 XML 消息格式.任何熟悉 SOAP 规范、使用任何编程语言的开发人员都可以为特定服务制定正确的 SOAP XML 请求,并通过获取以下服务详细信息来了解服务的响应.

SOAP provides a standard so that developers do not have to invent a custom XML message format for every service they want to make available. Given the signature of the service method to be invoked, the SOAP specification prescribes an unambiguous XML message format. Any developer familiar with the SOAP specification, working in any programming language, can formulate a correct SOAP XML request for a particular service and understand the response from the service by obtaining the following service details.

  • 服务名称
  • 服务实现的方法名称
  • 每个方法的方法签名
  • 服务实现的地址(表示为 URI)

使用 SOAP 简化了将现有软件组件公开为 Web 服务的过程,因为服务的方法签名标识了用于请求和响应的 XML 文档结构.

Using SOAP streamlines the process for exposing an existing software component as a Web service since the method signature of the service identifies the XML document structure used for both the request and the response.

这篇关于Document 风格和 RPC 风格的通信有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆