我搞不懂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消息”的协议吗?如果它们不同,那么我应该在什么时候使用SOAP消息,什么时候应该使用WSDL消息?
关于这一点的一些澄清将是很棒的。
发布于 2013-11-12 17:39:24
每个请求都会发送一个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描述了在服务器接收到消息时如何处理/处理该消息。在我们的例子中,它描述了标题、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也包含更多的信息,关于哪些函数链接在一起进行操作,哪些操作在服务中可用,以及您可以访问服务/操作的网络位置。
发布于 2013-01-27 04:08:11
WSDL (Web服务定义语言)是描述web服务的元数据文件。
例如操作名称、参数等。
soap消息是实际的有效负载
发布于 2017-04-25 04:58:42
比电话更好的类比:从邮购服务中通过邮寄订购产品。WSDL文档类似于说明如何创建服务提供者将接受的订单类型的说明。SOAP消息就像一个带有标准设计(大小、形状、结构)的信封,世界各地的邮局都知道如何处理。你把你的订单放进这样一个信封里。网络(例如互联网)就是邮政服务。你把你的信封放进邮件里。邮政服务的员工不会看信封里的东西。有效负载XML是您封装在信封中的定单。邮局投递信封后,web服务提供商打开信封并处理订单。如果您正确创建并填写了表单,他们会将您订购的产品邮寄回给您。
https://stackoverflow.com/questions/14541066
复制相似问题