文档风格和RPC风格通信有什么区别?

发布于 2024-12-29 22:01:46 字数 358 浏览 1 评论 0原文

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

无论哪种方式,我当前使用 JAX-WS 使用 @Webservice 注释服务,生成 WSDL,并从该 WSDL 生成客户端工件。

一旦收到这两种样式的工件,我就会调用端口上的方法。现在,RPC 风格和文档风格没有区别。那么有什么区别以及这种区别在哪里可见?

同样,基于 HTTP 的 SOAP 与基于 HTTP 的 XML 有何不同?毕竟 SOAP 也是具有 SOAP 命名空间的 XML 文档。

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.

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.

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

第七度阳光i 2025-01-05 22:01:46

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

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

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

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

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

当使用文字使用模型时,正文内容应符合用户定义的XML架构(XSD)结构强>。优点有两个。一方面,您可以使用用户定义的 XML 模式验证消息正文,此外,您还可以使用 XSLT 等转换语言来转换消息。

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

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

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

我建议您阅读这篇题为 我应该使用哪种 WSDL 风格? 的文章Russell Butek 对将 WSDL 绑定转换为 SOAP 消息的不同风格和使用模型以及它们的相对优点和缺点进行了很好的讨论。

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

你能发现差异的地方就是“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 消息将有空输出,如下所示:

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的客户端,输出为:

123
[123, 456]

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

文档样式响应:

<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 的形式带来一些复杂性,用于定义更丰富的内容
    数据类型。
  • 选择使用其中之一取决于
    操作/方法要求和预期客户。

同样,基于 HTTP 的 SOAP 与基于 HTTP 的 XML 有什么不同?后
所有的 SOAP 也是带有 SOAP 命名空间的 XML 文档。那么什么是
这里有什么区别吗?

为什么我们需要像 SOAP 这样的标准?通过通过 HTTP 交换 XML 文档,两个程序可以交换丰富的结构化信息,而无需引入 SOAP 等附加标准来显式描述消息信封格式和编码结构化内容的方法。

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

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

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

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

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

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.

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.

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

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.

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.

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

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.

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 Style:

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); 
}

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

RPC Style Response:

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

Document Style:

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);
}

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

123
[123, 456]

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:

Document Style Response:

<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>

Conclusion

  • 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.

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?

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 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.

  • Service name
  • Method names implemented by the service
  • Method signature of each method
  • Address of the service implementation (expressed as a URI)

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.

剩余の解释 2025-01-05 22:01:46

RPC 样式 Web 服务使用方法名称及其参数来生成表示方法调用堆栈的 XML 结构。文档样式指示 SOAP 主体包含可根据预定义的 XML 模式文档进行验证的 XML 文档。

一个好的起点: SOAP 绑定:文档样式 Web 服务与 RPC 样式 Web 服务之间的区别

An RPC style web service uses the names of the method and its parameters to generate XML structures representing a method’s call stack. Document style indicates the SOAP body contains an XML document which can be validated against pre-defined XML schema document.

A good starting point : SOAP Binding: Difference between Document and RPC Style Web Services

爱殇璃 2025-01-05 22:01:46

在 WSDL 定义中,绑定包含操作,这里是每个操作的样式。

文档: 在 WSDL 文件中,它指定具有内联或导入 XSD 文档的类型详细信息,该文档描述了由那些松散耦合的服务方法交换的复杂数据类型的结构(即模式)。文档样式是默认的。

  • 优点
    • 使用此文档样式,我们可以根据预定义的模式验证 SOAP 消息。它支持 xml 数据类型和模式。
    • 松散耦合。
  • 缺点:有点难以理解。

在 WSDL 类型元素中,如下所示:

<types>
 <xsd:schema>
  <xsd:import schemaLocation="http://localhost:9999/ws/hello?xsd=1" namespace="http://ws.peter.com/"/>
 </xsd:schema>
</types>

模式是从外部引用导入的。

RPC:在 WSDL 文件中,它不会创建类型模式,在消息元素中它定义名称和类型属性,从而实现紧密耦合。

<types/>  
<message name="getHelloWorldAsString">  
<part name="arg0" type="xsd:string"/>  
</message>  
<message name="getHelloWorldAsStringResponse">  
<part name="return" type="xsd:string"/>  
</message>  
  • 优点:易于理解。
  • 缺点
    • 我们无法验证 SOAP 消息。
    • 紧密耦合

RPC: WSDL 中没有类型
文档:类型部分将在 WSDL 中可用

In WSDL definition, bindings contain operations, here comes style for each operation.

Document : In WSDL file, it specifies types details either having inline Or imports XSD document, which describes the structure(i.e. schema) of the complex data types being exchanged by those service methods which makes loosely coupled. Document style is default.

  • Advantage:
    • Using this Document style, we can validate SOAP messages against predefined schema. It supports xml datatypes and patterns.
    • loosely coupled.
  • Disadvantage: It is a little bit hard to get understand.

In WSDL types element looks as follows:

<types>
 <xsd:schema>
  <xsd:import schemaLocation="http://localhost:9999/ws/hello?xsd=1" namespace="http://ws.peter.com/"/>
 </xsd:schema>
</types>

The schema is importing from external reference.

RPC :In WSDL file, it does not creates types schema, within message elements it defines name and type attributes which makes tightly coupled.

<types/>  
<message name="getHelloWorldAsString">  
<part name="arg0" type="xsd:string"/>  
</message>  
<message name="getHelloWorldAsStringResponse">  
<part name="return" type="xsd:string"/>  
</message>  
  • Advantage: Easy to understand.
  • Disadvantage:
    • we can not validate SOAP messages.
    • tightly coupled

RPC : No types in WSDL
Document: Types section would be available in WSDL

旧街凉风 2025-01-05 22:01:46

使用 JAX-WS RPC文档 样式的主要场景如下:

  • 使用远程过程调用 (RPC) 模式当消费者将 Web 服务视为具有封装数据的单个逻辑应用程序或组件时。请求和响应消息直接映射到过程调用的输入和输出参数。

    此类 RPC 模式的示例可能包括支付服务或股票报价服务。

  • 基于文档的模式用于以下情况:消费者将 Web 服务视为长期运行的业务流程,其中请求文档代表完整的信息单元。这种类型的网络服务可能涉及人工交互例如,如信贷申请请求文档与包含来自贷款机构的出价的响应文档。由于运行时间较长的业务流程可能无法立即返回所请求的文档,因此基于文档的模式更常见于异步通信体系结构中。 SOAP 的文档/文字变体用于实现基于文档的 Web 服务模式。

The main scenario where JAX-WS RPC and Document style are used as follows:

  • The Remote Procedure Call (RPC) pattern is used when the consumer views the web service as a single logical application or component with encapsulated data. The request and response messages map directly to the input and output parameters of the procedure call.

    Examples of this type the RPC pattern might include a payment service or a stock quote service.

  • The document-based pattern is used in situations where the consumer views the web service as a longer running business process where the request document represents a complete unit of information. This type of web service may involve human interaction for example as with a credit application request document with a response document containing bids from lending institutions. Because longer running business processes may not be able to return the requested document immediately, the document-based pattern is more commonly found in asynchronous communication architectures. The Document/literal variation of SOAP is used to implement the document-based web service pattern.

栖竹 2025-01-05 22:01:46

文档
可以根据预定义的模式验证文档样式消息。
在文档样式中,SOAP 消息作为单个文档发送。
架构示例:

  <types>  
   <xsd:schema> <xsd:import namespace="http://example.com/" 
    schemaLocation="http://localhost:8080/ws/hello?xsd=1"/>  
   </xsd:schema>  
  </types>

文档样式肥皂体消息示例

  <message name="getHelloWorldAsString">   
     <part name="parameters" element="tns:getHelloWorldAsString"/>   
  </message> 
  <message name="getHelloWorldAsStringResponse">  
     <part name="parameters"> element="tns:getHelloWorldAsStringResponse"/>   
  </message>

文档样式消息是松散耦合的。

RPC
RPC 风格的消息使用方法名称和参数来生成 XML 结构。
消息很难根据模式进行验证。
在 RPC 风格中,SOAP 消息会发送尽可能多的元素。

  <message name="getHelloWorldAsString">
    <part name="arg0"> type="xsd:string"/>   
   </message> 
  <message name="getHelloWorldAsStringResponse">   
    <part name="return"
   > type="xsd:string"/>   
  </message>

这里每个参数都是离散指定的,
RPC 风格的消息是紧密耦合的,通常是静态的,当方法签名更改时需要更改客户端
rpc 样式仅限于非常简单的 XSD 类型,例如 String 和 Integer,并且生成的 WSDL 甚至没有类型部分来定义和约束参数

Literal
默认样式。数据根据模式进行序列化,消息中未指定数据类型,但使用对模式(命名空间)的引用来构建肥皂消息。

   <soap:body>
     <myMethod>
        <x>5</x>
        <y>5.0</y>
     </myMethod>
   </soap:body>

编码
每个参数中指定的数据类型

   <soap:body>
     <myMethod>
         <x xsi:type="xsd:int">5</x>
         <y xsi:type="xsd:float">5.0</y>
     </myMethod>
   </soap:body>

架构自由

Document
Document style messages can be validated against predefined schema.
In document style, SOAP message is sent as a single document.
Example of schema:

  <types>  
   <xsd:schema> <xsd:import namespace="http://example.com/" 
    schemaLocation="http://localhost:8080/ws/hello?xsd=1"/>  
   </xsd:schema>  
  </types>

Example of document style soap body message

  <message name="getHelloWorldAsString">   
     <part name="parameters" element="tns:getHelloWorldAsString"/>   
  </message> 
  <message name="getHelloWorldAsStringResponse">  
     <part name="parameters"> element="tns:getHelloWorldAsStringResponse"/>   
  </message>

Document style message is loosely coupled.

RPC
RPC style messages use method name and parameters to generate XML structure.
messages are difficult to be validated against schema.
In RPC style, SOAP message is sent as many elements.

  <message name="getHelloWorldAsString">
    <part name="arg0"> type="xsd:string"/>   
   </message> 
  <message name="getHelloWorldAsStringResponse">   
    <part name="return"
   > type="xsd:string"/>   
  </message>

Here each parameters are discretely specified,
RPC style message is tightly coupled, is typically static, requiring changes to the client when the method signature changes
The rpc style is limited to very simple XSD types such as String and Integer, and the resulting WSDL will not even have a types section to define and constrain the parameters

Literal
By default style. Data is serialized according to a schema, data type not specified in messages but a reference to schema(namespace) is used to build soap messages.

   <soap:body>
     <myMethod>
        <x>5</x>
        <y>5.0</y>
     </myMethod>
   </soap:body>

Encoded
Datatype specified in each parameter

   <soap:body>
     <myMethod>
         <x xsi:type="xsd:int">5</x>
         <y xsi:type="xsd:float">5.0</y>
     </myMethod>
   </soap:body>

Schema free

黎夕旧梦 2025-01-05 22:01:46

我认为您要问的是 RPC Literal、Document Literal 和 Document Wrapped SOAP Web 服务之间的区别。

请注意,文档 Web 服务也被描述为文字并包装,它们是不同的 - 主要区别之一是后者符合 BP 1.1,而前者则不符合。

此外,在 Document Literal 中,要调用的操作不是根据其名称指定的,而在 Wrapped 中是这样的。我认为,在轻松找出请求所针对的操作名称方面,这是一个显着的差异。

就 RPC 文字与 Document Wrapped 而言,Document Wrapped 请求可以根据 WSDL 中的模式轻松审查/验证——这是一大优势。

由于其优点,我建议使用 Document Wrapped 作为 Web 服务类型的选择。

SOAP on HTTP是以HTTP为载体绑定的SOAP协议。 SOAP 也可以通过 SMTP 或 XXX 传输。 SOAP 提供了一种实体(例如客户端和服务器)之间交互的方式,并且两个实体都可以根据协议的语义来编组操作参数/返回值。

如果您在 HTTP 上使用 XML(并且您可以),那么它可以简单地理解为 HTTP 请求/响应上的 XML 有效负载。您需要提供框架来编组/解组、错误处理等。

包含 WSDL 示例和代码的详细教程,重点是 Java:SOAP 和 JAX-WS, RPC 与文档 Web 服务

I think what you are asking is the difference between RPC Literal, Document Literal and Document Wrapped SOAP web services.

Note that Document web services are delineated into literal and wrapped as well and they are different - one of the primary difference is that the latter is BP 1.1 compliant and the former is not.

Also, in Document Literal the operation to be invoked is not specified in terms of its name whereas in Wrapped, it is. This, I think, is a significant difference in terms of easily figuring out the operation name that the request is for.

In terms of RPC literal versus Document Wrapped, the Document Wrapped request can be easily vetted / validated against the schema in the WSDL - one big advantage.

I would suggest using Document Wrapped as the web service type of choice due to its advantages.

SOAP on HTTP is the SOAP protocol bound to HTTP as the carrier. SOAP could be over SMTP or XXX as well. SOAP provides a way of interaction between entities (client and servers, for example) and both entities can marshal operation arguments / return values as per the semantics of the protocol.

If you were using XML over HTTP (and you can), it is simply understood to be XML payload on HTTP request / response. You would need to provide the framework to marshal / unmarshal, error handling and so on.

A detailed tutorial with examples of WSDL and code with emphasis on Java: SOAP and JAX-WS, RPC versus Document Web Services

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文