What is SOAP

<< Click to Display Table of Contents >>

Navigation:  SOAP >

What is SOAP

Previous pageReturn to chapter overviewNext page

SOAP is an XML-based messaging protocol that allows programs that run on disparate operating systems to communicate via HyperText Transfer Protocol (HTTP) and its Extensible Markup Language (XML). SOAP originally stood for Simple Object Access Protocol, but version 1.2 of the standard dropped this acronym.

 

HTTP is the underlying application layer protocol used by the World Wide Web. It defines how messages are formatted and transmitted and what actions servers and browsers should take in response to various commands, such as fetching a Web page from a Web server in response to entering a URL into your browser (the client). This independent request-response interaction makes HTTP stateless; each command is executed without knowledge of the commands that came before it, making it ideal as a carrier for IDE real time transactions.

 

SOAP was designed as an object-access protocol in 1998 by Dave Winer, Don Box, Bob Atkinson, and Mohsen Al-Ghosein for Microsoft, where Atkinson and Al-Ghosein were working at the time. Because it was championed by Microsoft it was initially met with skepticism by those who believed it was the software giant's attempt to hijack a piece of the internet. That view has since changed and SOAP is now recognized as a common standard; its development is guided by the XML Protocol Working Group of the World Wide Web Consortium (W3C), the organization that guides most important Web standards.

 

Since Web protocols are installed and available for use by all major operating system platforms, HTTP and XML provide an at-hand solution that allows programs running under different operating systems in a network to communicate with each other. SOAP specifies exactly how to encode an HTTP header and an XML file so that a program in one computer can call a program in another and pass along information. SOAP also specifies how the called program will return a response. Despite its frequent pairing with HTTP, SOAP supports other transport protocols as well, such as SMTP.

 

SOAP defines the XML-based message format that Web service-enabled applications use to communicate and inter-operate with each other over the Web. The heterogeneous environment and of the Web demands that applications support a common data encoding protocol and message format. SOAP is a standard for encoding messages in XML that invoke functions in other applications. It is analogous to Remote Procedure Calls (RCP), used in many technologies such as DCOM and CORBA, but eliminates some of the complexities of using these interfaces. SOAP enables applications to call functions of other applications running on any hardware platform, regardless of their host operating systems or programming languages.

 

SOAP messages are more likely to get through firewall servers, since HTTP is typically Port 80 compliant, where other calls may be blocked for security reasons. Since HTTP requests are usually allowed to go through firewalls, no additional firewall or proxy configurations or exceptions are needed and programs using SOAP to communicate can be sure that the program can communicate with programs anywhere.

 

 

 

Anatomy

A message is sent via SOAP is in XML format, and is made up of four parts - and envelope, a header, a body, and a fault segment. The envelope encapsulates the message header and body and contains a variety of information required for processing the message, including a description of the kind of data to be found inside the envelope, and information about how that data should be processed. It also contains information about the sender and the recipient of the message.

 

Soap doesn't require that a message contain a header or fault segment, although as a practical matter messages will include the header when used in Web services. Information found in the header can perform a variety of functions, such as providing authentication. The data found in headers is organized into header blocks; there can be multiple blocks in a single header.

 

The body of the message is what contains the data. This might be a request for information or a response to a request for information. The data in the SOAP body is organized into sub-elements, of which there can be one or more.

 

The optional fault segment of the message contains any errors that occurred while processing the message.

 

The following is a simple example of a SOAP message requesting the stock price (GetStockPrice) of parameter StockName IBM:

 

Example message (simple):

 

POST /InStock HTTP/1.1

Host: www.example.org

Content-Type: application/soap+xml; charset=utf-8

Content-Length: 299

SOAPAction: "http://www.w3.org/2003/05/soap-envelope"

 

<?xml version="1.0"?>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

  <soap:Header>

  </soap:Header>

  <soap:Body>

    <m:GetStockPrice xmlns:m="http://www.example.org/stock">

      <m:StockName>IBM</m:StockName>

    </m:GetStockPrice>

  </soap:Body>

</soap:Envelope>

 

The following is a response to the previous SOAP GetStockPrice request where the Stock Price of IBM is returned in the GetStockPriceResponse message:

 

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>

 

The following is a more complex message: a request for a travel reservation being sent via SOAP. As you can see, the entire message itself is in XML format, as are all SOAP messages. Even if you are not able to understand all of what you see, if you take a few minutes to examine it, you'll be able to get a better sense of what each of the elements of a SOAP message do.

 

Example message (detailed):

 

<?xml version='1.0' ?> 

<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope"> 

    <env:Header> 

        <m:reservation xmlns:m="http://travelcompany.example.org/reservation" env:actor="http://www.w3.org/2001/12/soap-envelope/actor/next" env:mustUnderstand="true"> 

            <m:reference>uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d</m:reference> 

            <m:dateAndTime>2001-11-29T13:20:00.000-05:00</m:dateAndTime> 

        </m:reservation> 

        <n:passenger xmlns:n="http://mycompany.example.com/employees" env:actor="http://www.w3.org/2001/12/soap-envelope/actor/next" env:mustUnderstand="true"> 

            <n:name>John Q. Public</n:name> 

        </n:passenger> 

    </env:Header> 

    <env:Body> 

        <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel"> 

            <p:departure> 

                <p:departing>New York</p:departing> 

                <p:arriving>Los Angeles</p:arriving> 

                <p:departureDate>2001-12-14</p:departureDate> 

                <p:departureTime>late afternoon</p:departureTime> 

                <p:seatPreference>aisle</p:seatPreference> 

            </p:departure> 

            <p:return> 

                <p:departing>Los Angeles</p:departing> 

                <p:arriving>New York</p:arriving> 

                <p:departureDate>2001-12-20</p:departureDate> 

                <p:departureTime>mid morning</p:departureTime> 

                <p:seatPreference/> 

            </p:return> 

        </p:itinerary> 

        <q:lodging xmlns:q="http://travelcompany.example.org/reservation/hotels"> 

            <q:preference>none</q:preference> 

        </q:lodging> 

    </env:Body> 

</env:Envelope>