Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

SOAP Basics

This section reviews the basics of SOAP. After reading this section, you will be able to find your way through common SOAP interactions. The next section zooms in on some of these topics and provides the missing details.

At the time of writing, SOAP is not an official W3C standard. Two somewhat incompatible versions of SOAP coexist:

Note that SOAP 1.1 is not officially endorsed by W3C. It is available only on the W3C site as notes. Notes (as opposed to recommendations such as XML) are working documents prepared by W3C members and published for information only. Notes are intended to elicit comments.

The most visible difference between SOAP 1.1 and SOAP 1.2 is the use of XML namespaces. SOAP 1.1 builds all its namespaces from the http://schemas.xmlsoap.org/soap root, whereas SOAP 1.2 uses http://www.w3.org/2001/09/soap.


Because they use different namespaces, the two versions of SOAP are not directly compatible. Otherwise they are mostly similar.

The remainder of this article concentrates on the similarities and highlights the differences only where relevant.

Other differences are mostly editorial. SOAP 1.2 is better written: it contains fewer ambiguities and is generally easier to read.


If you have problems when reading the SOAP 1.1 specification, look up the corresponding section in the SOAP 1.2 spec.

SOAP Architecture

The most striking difference between SOAP and XML-RPC is that SOAP leaves so many options open. XML-RPC provided a closed solution to one problem: sending RPC requests over HTTP.

SOAP, on the other hand, is more like a toolbox. It defines a messaging framework (the envelope), encoding rules and a binding to the HTTP protocol. RPC needs all three but you can build SOAP requests with the envelope, the HTTP binding, and then use other encoding rules. Or you can use the envelope, the encoding rules, and another communication protocol.

Figure 1 illustrates this. At the bottom of the stack are HTTP and SMTP, two communication protocols developed independently from SOAP. They control sending and receiving files.

Figure 1 Logical view of SOAP.

SOAP attaches to those protocols through bindings (note that, at the time of writing, the SMTP binding is not official). On top of the binding comes the message framework that lays down the rules that organize SOAP messages. What goes in the messages? That's the role of the encoding rules. Finally the RPC uses the encoding rules to create a message, which is stored in an envelope (the message framework), and sent over HTTP.

Notice the ebXML Transport, Routing, and Packaging in Figure 1. The ebXML initiative develops e-commerce solutions with XML (see http://www.ebxml.org for more information). It uses the messaging framework and the SOAP bindings, but it has its own encoding rules. The ebXML initiative helps illustrate that SOAP is a toolbox from which you can pick and choose those elements that make sense for you.

Unfortunately, what is gained in flexibility is lost in simplicity. SOAP can be very confusing when you try to find your way through the maze of options. Also the options may result in incompatibilities. For example, although ebXML uses SOAP, it is not directly compatible with SOAP RPC because it does not use the same encoding rules.


If you ever get lost in the SOAP options, remember that, taken individually, each option is simple. Although the number of options may be confusing, they are not difficult to understand. If you understand how two options relate one to another, you should do fine.

SOAP Blocks and Elements

The messaging framework defines the basic XML elements you need to construct SOAP requests. SOAP defines the request in terms of SOAP blocks where a block is a single logical computational unit. The block is represented as an XML element identified by a qualified name, that is, a combination of local name and namespace.

XML Namespaces

A SOAP message contains elements defined by different sources: some are defined by the SOAP recommendation itself, others come from the XML schema recommendation and, finally, it is likely to also contain elements defined by the programmer.

The fact that different sources collaborate to create a document may cause conflicts and, in particular, naming conflicts.

XML namespaces is a standard mechanism (defined by the W3C) to avoid name conflicts. For example, if the programmer has defined a Body element, the namespace helps distinguish this Body element from the SOAP body. In that respect, namespaces are similar to Java packages.

To guarantee uniqueness, XML namespaces are URIs that are bound to prefixes through an xmlns attribute.

For example,

<env:Envelope xmlns:env=http://schemas.xmlsoap.org/soap/envelope/">

binds the http://schemas.xmlsoap.org/soap/envelope/ namespace with the env prefix. Only the prefix appears in the remainder of the document. For example:


The name after the prefix is said to be the local name. Again note the similarity with Java packages that also use domain names to guarantee the uniqueness of names.

Unfortunately, because SOAP uses HTTP, SOAP nodes are also identified by URIs, and this creates some confusion. To avoid confusion, remember that URIs to xmlsoap.org and w3.org are likely to be namespaces.

SOAP defines four XML elements:

  • env:Envelope is the root of the SOAP request. At the minimum, it defines the SOAP namespace (http://schemas.xmlsoap.org/soap/envelope/ for SOAP 1.1 and http://www.w3.org/2001/09/soap-envelope for SOAP 1.2; the latter URI is likely to change). It may define additional namespaces.

  • env:Header contains auxiliary information, as SOAP blocks, such as authentication, routing information, or transaction identifier. The header is optional.

  • env:Body contains the main information in one or more SOAP blocks. An example would be a SOAP block for RPC call. The body is mandatory and it must appear after the header.

  • env:Fault is a special block that indicates protocol-level errors. If present, it must appear in the body.


The SOAP 1.1 specification uses SOAP-ENV for the prefix throughout the specification. Consequently most SOAP 1.1 libraries use the SOAP-ENV prefix. This article uses env, as in the SOAP 1.2 recommendation. Bear in mind that the prefix is irrelevant as long as the URI remains correct.

Figure 2 illustrates the physical organization of a SOAP message. Notice that the header appears before the body.

Figure 2 Physical layout of a SOAP message.

SOAP requests may be sent directly to the server or they may be routed through one or more so-called SOAP nodes. A typical example is when a message is routed through proxies on its way to the final recipient, as Figure 3 illustrates.

Figure 3 Forwarding a message through a proxy.

Some or all the SOAP blocks in the headers may be targeted to intermediary SOAP nodes, as was shown in Figure 3. In this example, the header contains routing information that is intended for the proxy only. Notice that the proxy has processed and removed the information from the message it forwards to the ultimate recipient. Unlike the header, the body is always routed to the ultimate SOAP node unmodified.

Encoding Styles

With the exception of the env:Fault element, which signals protocol errors, SOAP leaves it up to you to decide what goes in the header and body. Still, SOAP defines a so-called encoding style to create XML documents from data structures. The SOAP encoding style defines XML equivalents for data structures commonly found in programming languages: simple types (integer, string, and the like), arrays, and structures.

For arrays and structures, SOAP defines an accessor, which is an identifier for the data. In an array, the accessor is the position of the element; in a structure, the accessor is the name field.

SOAP maps all the information to XML elements. For example, a name field will become a name element in the XML document. Instances of the Java class in Listing 7 are represented with the XML document in Listing 8 (using SOAP 1.2 namespaces).

Listing 7—Resource.java

package com.psol.resourceful;

public class Resource
  public int id = -1;
  public String name = null,
         description = null;

Listing 8—SOAP Encoding for a Resource

<?xml version="1.0"?>
<rs:Resource xmlns:rs="http://www.psol.com/2001/resourceful"
  <id xsi:type="xsd:int">0</id>
  <description>Our largest meeting room</description>

SOAP defines the env:encodingStyle attribute to indicate the rules used to create a document. The value of env:encodingStyle is a list of URIs that identify the rules to decode the document. The attribute may be attached to any element and its scope extends to the descendant of the element (not unlike XML namespaces).

The URIs for SOAP's own encoding rules are http://schemas.xmlsoap.org/soap/encoding/ for SOAP 1.1 and http://www.w3.org/2001/09/soap-envelope for SOAP 1.2. You can see the env:encodingStyle attribute on line 6 of Listing 8.

Transport Options

SOAP defines an HTTP binding. Essentially a SOAP message is sent using the POST verb. HTTP also supports GET, HEAD, and PUT, but SOAP does not use them.

SOAP with attachments is an extension to SOAP 1.1 that supports sending attachments next to the SOAP body. Attachments are similar to mail attachments and may include images or other files.

Although it only defines the binding for HTTP, the SOAP recommendation makes it clear that binding SOAP to other protocols is possible. In practice, there's great interest in binding SOAP over SMTP, the email protocol. Obviously, when bound over SMTP, SOAP provides one-way communication only: A message is sent but there is no response. If the recipient wants to reply, it needs to send another request.


Armed with encoding rules, an envelope, and HTTP binding, it's not difficult to support RPC. For SOAP, an RPC request is a structure where each in and in/out parameter is given its own accessor. For example, a call to the Java method getFreeResourcesOn(Date start,Date end) is encoded as the following structure:

struct GetFreeResourcesOn {
  TimeInstant start;
  TimeInstant end;

or, using the SOAP encoding rules introduced in the earlier "Encoding Styles" section (using SOAP 1.1 namespaces):

<?xml version='1.0'?>
<start xsi:type="xsd:timeInstant">2001-01-15T00:00:00Z</start>
<end xsi:type="xsd:timeInstant">2001-01-17T00:00:00Z</end>

The response is also a struct with one accessor for the return value and one accessor for each of the out and in/out parameters.


Java does not support in/out or out parameters. It supports only in parameters.

  • + Share This
  • 🔖 Save To Your Account

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.


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.


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.


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.


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


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


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.


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.


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