Soap is a simple XML-based protocol that allows applications to exchange information over HTTP.
Or, more simply, soap is the protocol used to access network services.
Communication between applications through HTTP is better because HTTP is supported by all Internet browsers and servers. Soap is created to complete this task.
Soap provides a standard method that allows applications running on different operating systems and using different technologies and programming languages to communicate with each other.
The basic web services platform is XML + HTTP.
· Soap refers to Simple Object Access Protocol
· Soap is a communication protocol.
· Soap is used for communication between applications
· Soap is a message sending format.
· Soap is designed to communicate over the Internet
· Soap is independent from the platform
· Soap is independent of languages
· Soap is based on XML
· Soap is simple and scalable
· SOAP allows you to bypass the Firewall
· Soap will be developed as W3C standards
Microsoft and soap
Soap is a key element of Microsoft. NET architecture and is used for future Internet application development.
Soap build Module
A soap message is a common XML document that contains the following elements:
- The required envelope element. This XML document can be identified as a SOAP message.
- Optional Header elements, including header information
- Required body elements, including all call and response information
- An optional fault element that provides information about errors that occur when processing the message.
All the above elements are declared in the default namespace for soap encapsulation:
Http://www.w3.org/2001/12/soap-envelope
And the default namespace for soap encoding and data types:
Http://www.w3.org/2001/12/soap-encoding
Syntax Rules
Here are some important syntax rules:
· Soap messages must be encoded using XML.
· Soap messages must use the SOAP envelope namespace
· Soap messages must use the soap encoding namespace
· Soap messages cannot contain DTD references
· Soap messages cannot contain XML processing instructions
Basic Structure of soap messages
<? 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>
The envelope element of the forced soap is the root element of the SOAP message.
SOAP envelope element
The required SOAP envelope element is the root element of the SOAP message. It defines an XML document as a SOAP message.
Note xmlns: Use of the soap namespace. Its value should always be:
http://www.w3.org/2001/12/soap-envelope
And it can define encapsulation as soap encapsulation:
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ... Message information goes here ...</soap:Envelope>
Xmlns: Soap namespace
A soap message must have an envelope element associated with the namespace "http://www.w3.org/2001/12/soap-envelope.
If different namespaces are used, an error occurs in the application and the message is discarded.
Encodingstyle attributes
The encodingstyle attribute of soap is used to define the data type used in the document. This attribute can appear in any soap element and will be applied to the content of the element and all child elements of the element. No default encoding method is available for soap messages.
Syntax
soap:encodingStyle="URI"
Instance
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">...Message information goes here...</soap:Envelope>
The optional SOAP Header element contains header information.
SOAP Header element
Optional SOAP header elements can contain application-specific information (such as authentication and payment) about soap messages ). If the Header element is provided, it must be the first child element of the envelope element.
Note: The direct sub-elements of all header elements must be qualified namespaces.
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header><m:Transxmlns:m="http://www.w3school.com.cn/transaction/"soap:mustUnderstand="1">234</m:Trans></soap:Header>......</soap:Envelope>
The preceding example contains a header with a "trans" element. Its value is 234. The value of the "mustunderstand" attribute of this element is "1 ".
In the default namespace ("http://www.w3.org/2001/12/soap-envelope"), Soap defines three attributes. These three attributes are: Actor, mustunderstand, and encodingstyle. These attributes defined in the SOAP header can define how the container processes soap messages.
Actor attributes
By passing through different endpoints along the message path, soap messages can be transmitted from a sender to a receiver. Not all parts of a SOAP message are intended to be transmitted to the end endpoint of the SOAP message. However, another aspect may be intended to be transmitted to one or more endpoints on the message path.
The actor attribute of soap can be used to address the Header element to a specific endpoint.
Syntax
soap:actor="URI"
Instance
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header><m:Transxmlns:m="http://www.w3school.com.cn/transaction/"soap:actor="http://www.w3school.com.cn/appml/">234</m:Trans></soap:Header>......</soap:Envelope>
Mustunderstand attributes
The mustunderstand attribute of soap can be used to identify whether a title item is mandatory or optional for the recipient to process it.
If you add "mustunderstand =" 1 "to a child element of the header, it indicates that the recipient processing this header must recognize this element. If the recipient cannot recognize this element, it must be invalid when processing this header.
Syntax
soap:mustUnderstand="0|1"
Instance
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header><m:Transxmlns:m="http://www.w3school.com.cn/transaction/"soap:mustUnderstand="1">234</m:Trans></soap:Header>......</soap:Envelope>
The forced soap Body element contains the actual SOAP message.
Soap body Element
The required soap Body element can contain the actual SOAP message to be sent to the Message endpoint.
The direct sub-element of the soap Body element can be a qualified namespace. In the default namespace ("http://www.w3.org/2001/12/soap-envelope"), Soap defines an element inside the body element. That is, the fault element of soap, used to indicate error messages.
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body> <m:GetPrice xmlns:m="http://www.w3school.com.cn/prices"> <m:Item>Apples</m:Item> </m:GetPrice></soap:Body></soap:Envelope>
The above example requests the price of apple. Note that the above M: getprice and item elements are application-specific elements. They are not part of the soap standard.
A soap response should be similar to the following:
<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body> <m:GetPriceResponse xmlns:m="http://www.w3school.com.cn/prices"> <m:Price>1.90</m:Price> </m:GetPriceResponse></soap:Body></soap:Envelope>
HTTP protocol
HTTP communicates over TCP/IP. The HTTP client uses TCP to connect to the HTTP server. After a connection is established, the client can send an HTTP request message to the server:
POST /item HTTP/1.1Host: 189.123.345.239Content-Type: text/plainContent-Length: 200
The server then processes the request and sends an HTTP Response to the client. This response contains the status code indicating the Request status:
200 OKContent-Type: text/plainContent-Length: 200
In the preceding example, the server returns a 200 status code. This is the standard success code of HTTP.
If the server cannot decode the request, it may return such information:
400 Bad RequestContent-Length: 0
Soap HTTP binding
A soap method is an HTTP request/response that complies with the soap encoding rules.
HTTP + xml = soap
The soap request may be an http post or http get request.
The http post request requires at least two HTTP headers: Content-Type and Content-Length.
Content-Type
The Content-Type header of the SOAP request and response defines the MIME type of the message and the character encoding of the XML Entity used for the request or response (optional ).
Syntax
Content-Type: MIMEType; charset=character-encoding
Example
POST /item HTTP/1.1Content-Type: application/soap+xml; charset=utf-8
Content-Length
The Content-Length header of the SOAP request and response specifies the number of bytes of the request or response body.
Syntax
Content-Length: bytes
Example
POST /item HTTP/1.1Content-Type: application/soap+xml; charset=utf-8Content-Length: 250
A soap instance
In the following example, A getstockprice request is sent to the server. This request has a stockname parameter, and a price parameter is returned in the response. The namespace for this feature is defined in this address: "http://www.example.org/stock"
SOAP request:
POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><soap:Envelopexmlns: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 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><soap:Envelopexmlns: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>