SOAP消息和WSDL之间的区别? [英] Difference between a SOAP message and a WSDL?

查看:250
本文介绍了SOAP消息和WSDL之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SOAP消息和WSDL如何组合在一起感到困惑?我已经开始研究SOAP消息,例如:

I am confused about how SOAP messages and WSDL fit together? I have started looking into SOAP messages such as:

    POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>

所有SOAP消息都是WSDL的吗? SOAP是一种接受自己的SOAP消息还是WSDL的协议?如果它们不同,那么我什么时候应该使用SOAP消息?何时应该使用WSDL?

Are all SOAP messages WSDL's? Is SOAP a protocol that accepts its own 'SOAP messages' or 'WSDL's? If they are different, then when should I use SOAP messages and when should I use WSDL's?

对此进行一些澄清将是非常棒的。

Some clarification around this would be awesome.

推荐答案

每个请求都会发送一个SOAP文档。假设我们是一家书店,并且我们查询了一台远程服务器,以了解特定书籍的当前价格。假设我们需要将Book的标题,页数和ISBN号传递给服务器。

A SOAP document is sent per request. Say we were a book store, and had a remote server we queried to learn the current price of a particular book. Say we needed to pass the Book's title, number of pages and ISBN number to the server.

每当我们想知道价格时,我们都会发送一个唯一的SOAP消息。它看起来像这样;

Whenever we wanted to know the price, we'd send a unique SOAP message. It'd look something like this;

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <m:GetBookPrice xmlns:m="http://namespaces.my-example-book-info.com">
      <ISBN>978-0451524935</ISBN>
      <Title>1984</Title>
      <NumPages>328</NumPages>
    </m:GetBookPrice>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope> 

我们希望得到一条SOAP响应消息,如:

And we expect to get a SOAP response message back like;

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <m:GetBookPriceResponse xmlns:m="http://namespaces.my-example-book-info.com">
      <CurrentPrice>8.99</CurrentPrice>
      <Currency>USD</Currency>
    </m:GetBookPriceResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

然后,WSDL描述了当服务器收到此消息时如何处理/处理此消息。在我们的例子中,它描述了Title,NumPages& ISBN是,我们是否应该期待GetBookPrice消息的响应以及响应应该是什么样的。

The WSDL then describes how to handle/process this message when a server receives it. In our case, it describes what types the Title, NumPages & ISBN would be, whether we should expect a response from the GetBookPrice message and what that response should look like.

类型看起来像这样;

<wsdl:types>

  <!-- all type declarations are in a chunk of xsd -->
  <xsd:schema targetNamespace="http://namespaces.my-example-book-info.com"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema">

    <xsd:element name="GetBookPrice">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ISBN" type="string"/>
          <xsd:element name="Title" type="string"/>
          <xsd:element name="NumPages" type="integer"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>

    <xsd:element name="GetBookPriceResponse">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="CurrentPrice" type="decimal" />
          <xsd:element name="Currency" type="string" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>

  </xsd:schema>
</wsdl:types>

但WSDL还包含更多信息,关于哪些功能链接在一起以进行操作,以及哪些操作是在服务中可用,以及网络上的行踪,您可以访问服务/操作。

But the WSDL also contains more information, about which functions link together to make operations, and what operations are avaliable in the service, and whereabouts on a network you can access the service/operations.

另见 W3带注释的WSDL示例

这篇关于SOAP消息和WSDL之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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