文档样式和RPC样式通信之间有什么区别? [英] What is the difference between Document style and RPC style communication?

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

问题描述

有人可以向我解释一下Document和RPC样式的Web服务之间的区别吗?除了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样式和Document样式上没有什么不同.那么有什么区别?在哪里可以看到区别?

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?

类似地,HTTP上的SOAP与HTTP上的XML有什么不同?毕竟,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样式的Web服务?

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架构(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?

可以找到差异的地方是响应"!

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批注的style属性来完成此更改.下面显示了具有更丰富数据类型的第二种方法的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样式的基本缺点是,它没有 支持更丰富的数据类型,而使用文档样式"的是 以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.

类似地,HTTP上的SOAP与HTTP上的XML有什么不同?后 所有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.

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

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