gpt4 book ai didi

java - SOAP 消息和 WSDL 之间的区别?

转载 作者:IT老高 更新时间:2023-10-28 11:25:02 25 4
gpt4 key购买 nike

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

    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”的协议(protocol)吗?如果它们不同,那么我应该什么时候使用 SOAP 消息,什么时候应该使用 WSDL?

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

最佳答案

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

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

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

<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 消息的响应以及该响应应该是什么样子。

类型看起来像这样;

<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 还包含更多信息,包括哪些功能链接在一起进行操作、服务中可用的操作以及您可以访问服务/操作的网络位置。

另见 W3 Annotated WSDL Examples

关于java - SOAP 消息和 WSDL 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14541066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com