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

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

问题描述

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

 POST/InStock HTTP/1.1主持人:www.example.org内容类型:应用程序/soap+xml;字符集=utf-8内容长度:nnn<?xml version="1.0"?><肥皂:信封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?

对此进行一些澄清会很棒.

解决方案

每个请求都会发送一个 SOAP 文档.假设我们是一家书店,有一个远程服务器,我们可以查询某本书的当前价格.假设我们需要将书名、页数和 ISBN 号传递给服务器.

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

<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 响应消息,如;

<SOAP-ENV:Body><m:GetBookPriceResponse xmlns:m="http://namespaces.my-example-book-info.com"><CurrentPrice>8.99</CurrentPrice><货币>美元</货币></m:GetBookPriceResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

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

类型看起来像这样;

<!-- 所有类型声明都在 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:序列><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:序列><xsd:element name="CurrentPrice" type="decimal"/><xsd:element name="Currency" type="string"/></xsd:sequence></xsd:complexType></xsd:element></xsd:schema></wsdl:types>

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

另请参见 W3 带注释的 WSDL 示例>

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>

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.

解决方案

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.

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> 

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>

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.

The types would look like this;

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

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.

See also W3 Annotated WSDL Examples

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

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