SOAP和HTTP 小疑惑

SOAP: simple object access protocol,使用HTTP进行传输,用于解决RPC(Remote Procedure Call).

传统 http的request body传递的是文本. 

当给http的header设置SOAPAction(它的值为server的url)时,就指定了这次请求为Soap 请求。request body是xml格式的。Envelope里面记录着要调用的方法名,如果该方法还有参数的话,还会有参数名和值。

如下,一次请求和应答:

POST /StockQuote HTTP/1.1
Host: www.server.com
Content-Type: text/xml; 
charset="utf-8"
Content-Length: 555
SOAPAction: "Server-URI"

<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:GetLastTradePrice xmlns:m="Server-URI">   
  <symbol>DIS</symbol>
</m:GetLastTradePrice>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; 
charset="utf-8"
Content-Length:555

<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:GetLastTradePriceResponse xmlns:m="Server-URI">
           <Price>34.5</Price>
       </m:GetLastTradePriceResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP协议可以简单地理解为:SOAP=RPC+HTTP+XML,即采用HTTP作为通信协议,RPC作为一致性的调用途径,XML作为数据传送的格式,从而允许服务提供者和服务客户经过防火墙在Internet上进行通信交互。
SOAP还可以与其他传输协议搭配使用,TCP,UDP,SMTP,MIME都可以。

猜你喜欢

转载自www.cnblogs.com/Gift/p/10334168.html