Home > Articles

The SOAP Protocol

This chapter is from the book

The SOAP Messaging Framework

The first part of the SOAP specification is primarily concerned with defining how SOAP messages are structured and the rules processors must abide by when producing and consuming them. Let's look at a sample SOAP message, the inventory check request described in our earlier example:

NOTE

All the wire examples in this book have been obtained by using the tcpmon tool, which is included in the Axis distribution you can obtain with the example package from the Sams Web site. Tcpmon (short for TCP monitor) allows you to record the traffic to and from a particular TCP port, typically HTTP requests and responses. We'll go into detail about this utility in Chapter 5.

POST /axis/InventoryCheck.jws HTTP/1.0 Content-Type: application/soap+xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
 <doCheck soapenv:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
  <arg0 xsi:type="soapenc:string"
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">947-TI</arg0>
  <arg1 xsi:type="soapenc:int"
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">3</arg1>
 </doCheck>
 </soapenv:Body>
</soapenv:Envelope>

This is clearly an XML document (Chapter 2, "XML Primer," covered XML in detail), which has been sent via an HTTP POST. We've removed a few of the nonrelevant HTTP headers from the trace, but we left the content-type header, which indicates that this POST contains a SOAP message (note that this content-type would be different for SOAP 1.1—see the sidebar for details). We'll cover the HTTP-specific parts of SOAP interactions further a bit later in the chapter.

The root element is soapenv:Envelope, in the http://www.w3.org/2003/05/soap-envelope namespace, which surrounds a soapenv:Body containing application-specific content that represents the central purpose of the message. In this case we're asking for an inventory check, so the central purpose is the doCheck element. The Envelope element has a few useful namespace declarations on it, for the SOAP envelope namespace and the XML Schema data and instance namespaces.

SOAP 1.1 Difference: Identifying SOAP Content

The SOAP 1.1 envelope namespace is http://schemas.xmlsoap.org/soap/envelope/, whereas for SOAP 1.2 it has changed to http://www.w3.org/2003/05/soap-envelope. This namespace is used for defining the envelope elements and for versioning, which we will explain in more detail in the "Versioning in SOAP" section.

The content-type used when sending SOAP messages across HTTP connections has changed as well—it was text/xml for SOAP 1.1 but is now application/soap+xml for SOAP 1.2. This is a great improvement, since text/xml is a generic indicator for any type of XML content. The content type was so generic that machines had to use the presence of a custom HTTP header called SOAPAction: to tell that XML traffic was, in fact, SOAP (see the section on the HTTP binding for more). Now the standard MIME infrastructure handles this for us.

The doCheck element represents the remote procedure call to the inventory check service. We'll talk more about using SOAP for RPCs in a while; for now, notice that the name of the method we're invoking is the name of the element directly inside the soapenv:Body, and the arguments to the method (in this case, the SKU number and the quantity desired) are encoded inside the method element as arg0 and arg1. The real names for these parameters in Java are SKU and quantity; but due to the ad-hoc way we're calling this method, the client doesn't have any way of knowing that information, so it uses the generated names arg0 and arg1.

The response to this message, which comes back across in the HTTP response, looks like this:

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

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
  xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
 <doCheckResponse
    soapenv:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
  <rpc:result xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">return</rpc:result>
  <return xsi:type="xsd:boolean">true</return>
 </doCheckResponse>
 </soapenv:Body>
</soapenv:Envelope>

The response is also a SOAP envelope, and it contains an encoded representation of the result of the RPC call (in this case, the Boolean value true).

What good is having this envelope structure, when we could send our XML formats directly over a transport like HTTP without a wrapper? Good question; as we answer it, we'll examine some more details of the protocol.

Vertical Extensibility

Let's say you want your purchase order to be extensible. Perhaps you want to include security in the document someday, or you might want to enable a notarization service to associate a token with a particular purchase order, as a third-party guarantee that the PO was sent and contained particular items. How might you make that happen?

You could drop extensibility elements directly into your document before sending it. If we took the purchase order from the last chapter and added a notary token, it might look something like this:

<po id="43871" submitted="2004-01-05" customerId="73852">
 <notary:token xmlns:notary="http://notaries-r-us.com">
  XQ34Z-4G5
 </notary:token>
 <billTo>
  <company>The Skateboard Warehouse</company>
  ...
 </billTo>
 ...
</po>

To do things this way, and make it easy for your partners to use, you'd need to do two things. First, your schema would have to be explicitly extensible at any point in the structure where you might want to add functionality later (this can be accomplished in a number of ways, including the xsd:any/ schema construct); otherwise, documents containing extension elements wouldn't validate. Second, you would need to agree on rules by which those extensibility elements were to be processed—which ones are optional, which ones affect which parts of the document, and so on. Both of these requirements present challenges. Not all schemas have been designed for extensibility, and you may need to extend a document that follows a preexisting standard format that wasn't built that way. Also, processing rules might vary from document type to document type, so it would be challenging to have a uniform model with which to build a common processor. It would be nice to have a standardized framework for implementing arbitrary extensibility in a way that everyone could agree on.

It turns out that the SOAP envelope, in addition to containing a body (which must always be present), may also contain an optional Header element—and the SOAP Header structure gives us just what we want in an XML extensibility system. It's a convenient and well-defined place in which to put our extensibility elements. Headers are just XML elements that live inside the soapenv:Header/soapenv:Header tags in the envelope. The soapenv:Header always appears, incidentally, before the soapenv:Body if it's present. (Note that in the SOAP 1.2 spec, the extensibility elements are known as header blocks. However, the industry—and the rest of this book—colloquially refers to them simply as headers.)

Let's look at the extensibility example recast as a SOAP message with a header:

<soapenv:Envelope
  xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
 <soapenv:Header>
 <notary:token xmlns:notary="http://notaries-r-us.com">
  XQ34Z-4G5
 </notary:token>
 </soapenv:Header>
 <soapenv:Body>
 <PO>
  ...normal purchase order here...
 </PO>
 </soapenv:Body>
</soapenv:Envelope>

Since the SOAP envelope wraps around whatever XML content you want to send in the body (the PO, in this example), you can use the Header to insert extensions (the notary:token header) without modifying the central core of the message. This can be compared to a situation in real life where you want to send a document and some auxiliary information, but you don't want to mark up the document—so you put the document inside an envelope and then add another piece of paper or two describing your extra information.

Each individual header represents one piece of extensibility information that travels with your message. A lot of other protocols have this same basic concept—we're all familiar with the email model of headers and body. HTTP also contains headers, and both email and HTTP use the concept of extensible, user-defined headers. However, the headers in protocols like these are simple strings; since SOAP uses XML, you can encode much richer data structures for individual headers. Also, you can use XML's structure to make processing headers much more powerful and flexible than a basic string-based model.

Headers can contain any sort of data imaginable, but typically they're used for two purposes:

  • Extending the messaging infrastructure—Infrastructure headers are typically processed by middleware. The application doesn't see the headers, just their effects. They could be things like security credentials, correlation IDs for reliable messaging, transaction context identifiers, routing controls, or anything else that provides services to the application.

  • Defining orthogonal data—The second category of headers is application defined. These contain data that is orthogonal to the body of the message but is still destined for the application on the receiving side. An example might be extra data to accompany nonextensible schemas—if you wanted to add more customer data fields but couldn't change the billTo element, for instance.

Using headers to add functionality to messages is known as vertical extensibility, because the headers build on top of the message. A little later we'll discuss horizontal extensibility as well.

Now that you know the basics, we'll consider some of the additional framework that SOAP supplies for headers and how to use it. After that, we'll explain the SOAP processing model, which is the key to SOAP's scalability and expressive power.

The mustUnderstand Flag

Some extensions might use headers to carry data that's nice to know but not critical to the main purpose of the SOAP message. For instance, you might be invoking a "buy book" operation on a store's Web service. You receive a header in the response confirmation message that contains a list of other books the site thinks you might find interesting. If you know how to process that extension, then you might offer a UI to access those books. But if you don't, it doesn't matter—your original request was still processed successfully. On the other hand, suppose the request message of that same "buy book" operation contained private information (such as a credit card number). The sender might want to encrypt the XML in the SOAP body to prevent snooping. To make sure the other side knows what to do with the postencryption data inside the body, the sender inserts a header that describes how to decrypt the message. That header is important, and anyone trying to process the message without correctly processing the header and decrypting the body is going to run into trouble.

This is why we have the mustUnderstand g attribute, which is always in the SOAP envelope namespace. Here's what our notary header would look like with that attribute:

 <notary:token xmlns:notary="http://notaries-r-us.com"
   soapenv:mustUnderstand="true">
  XQ34Z-4G5
 </notary:token>

By marking things mustUnderstand (when we refer to headers "marked mustUnderstand," we mean having the soapenv:mustUnderstand attribute set to true), you're saying that the receiver must agree to all the terms of your extension specification or they can't process the message. If the mustUnderstand attribute is set to false or is missing, the header is defined as optional—in this case, processors not familiar with the extension can still safely process the message and ignore the optional header.

SOAP 1.1 Difference: mustUnderstand

In SOAP 1.2, the mustUnderstand attribute may have the values 0/false (false) or 1/true (true). In SOAP 1.1, despite the fact that XML allows true and false for Boolean values, the only legal mustUnderstand values are 0 and 1.

The mustUnderstand attribute is a key part of the SOAP processing model, since it allows you to build extensions that fundamentally change how a given message is processed in a way that is guaranteed to be interoperable. Interoperable here means that you can always know how to gracefully fail in the face of extensions that aren't understood.

SOAP Modules

When you implement a semantic using SOAP headers, you typically want other parties to use your extension, unless it's purely for internal use. As such, you typically write a specification that details all the constraints, rules, preconditions, and data formats of your extension. These specifications are known as SOAP modules. Modules are named with URIs so they can be referenced, versioned, and reasoned about. We'll talk more about module specifications when we get to the SOAP binding framework a bit later.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020