Soap learning process

1. What is SOAP?

  • SOAP refers to the Simple Object Access Protocol
  • SOAP is a protocol
  • SOAP for communication between applications
  • SOAP is a format for transmitting messages
  • SOAP is designed to communicate via the Internet
  • SOAP is platform independent
  • SOAP is independent of the language
  • SOAP-based XML
  • SOAP is simple and extensible
  • SOAP allows you to bypass the firewall
  • SOAP will be developed as a W3C standard

2.SOAP building blocks

A SOAP message is an ordinary XML document containing the following elements:

  • Envelope essential elements of the XML document can be identified as a SOAP message
  • The optional Header element that contains header information
  • Required Body element that contains all of the call and response information
  • Optional Fault element that provides information about errors that occurred in the handling of this message

3. syntax rules

Here are some important syntax rules:

  • SOAP message must be encoded in XML
  • SOAP message must use the SOAP Envelope namespace
  • SOAP message must use the SOAP Encoding namespace
  • SOAP message must not contain a DTD reference
  • XML SOAP message can contain processing instructions

Code Example:

<?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:Header>
  ...
  ...
</soap:Header>

<soap:Body>
  ...
  ...
  <soap:Fault>
    ...
    ...
  </soap:Fault>
</soap:Body>

</soap:Envelope>

 

 4. A SOAP example

In the following example, a request is sent to GetStockPrice server. StockName a request parameter, the response is returned in a Price parameter. This function namespace is defined in this address: "http://www.example.org/stock"

SOAP request:

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

HTTP/1.1 200 OK
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:GetStockPriceResponse>
      <m:Price>34.5</m:Price>
    </m:GetStockPriceResponse>
  </soap:Body>
  
</soap:Envelope>

 

Guess you like

Origin www.cnblogs.com/yxcn/p/11387443.html