Home > Articles > Programming > Java

This chapter is from the book

This chapter is from the book

The SOAP Encoding

The specification goes on at great length over the encoding. In this article, we can point out only the most important rules; turn to the specification itself if you need more details.

CAUTION

Unlike traditional middleware, SOAP does not explicitly map its encoding to programming languages. In other words, there is no standard SOAP mapping for Java. Therefore, two different implementations of SOAP may produce different encoding for the same objects.

Encoding Fields

The most basic rule is that values are always encoded in elements. For example, a name field is encoded as:

<name>Board room</name>

but not as:

<item name="Board room"/>

SOAP uses attributes exclusively to modify the default processing of an element. For example, the env:actor attribute indicates which node should process the element.

Simple Types

SOAP supports the simple types defined in the XML schema, Part 2: Datatypes recommendation (http://www.w3.org/TR/2001/REC-xmlschema-2-20010502). The most commonly used types are as follows:

  • string

  • base64Binary

  • integer, byte, short, int, long

  • decimal, float, double

  • boolean

  • dateTime, time, date, duration

Note that base64Binary supports binary objects.

CAUTION

SOAP 1.1 uses an earlier draft of XML schema that is identified with the http://www.w3.org/1999/XMLSchema-instance namespace URI.

Simple types are encoded as XML elements. If required, the xsi:type attribute may disambiguate the type. For example, a date might be encoded as:

<start xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xsi:type="xsd:dateTime">2001-01-15T00:00:00Z</start>

SOAP states that the xsi:type must be used when the type of the element cannot be deduced from its name. In practice, this is a major source of interoperability problems between SOAP implementations.

Indeed, different programming languages have different needs for the use of xsi:type. For example, Java is strongly typed and Java implementations use the xsi:type attribute liberally. Languages with less restrictive type systems may ignore the xsi:type attribute, which leads to conflicts.

Note that using valid XML documents (that is, documents with an XML schema) may help reduce ambiguities. However, as of this writing, no SOAP implementation uses schemas.

Compound Types: Structs

The encoding recognizes two compound types:

  • A structure (struct) is a list of elements logically grouped together. The elements are identified by their names. (The element accessor is its name.)

  • The array is a group of values identified not by their names but by their ordinal positions. (The accessor of the element is the position of the element in the array.)

Structures are encoded as accessor elements. (In most cases, the element borrows its name from the name of the struct in the programming language.) The fields are encoded as accessor elements. Having accessors whose names are local to their containing types results in unqualified elements; other elements are always qualified with a namespace.

You already saw how to encode a structure in Listing 8 (reproduced here for your convenience):

<?xml version="1.0"?>
<rs:Resource xmlns:rs="http://www.psol.com/2001/resourceful"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <id xsi:type="xsd:int">0</id>
  <name xsi:type="xsd:string">Auditorium</name>
  <description xsi:type="xsd:string">Our largest meeting room
    </description>
</rs:Resource>

Compound Type: Arrays

Arrays are encoded as elements of type enc:Array (or a type derived from enc:Array) where enc is bound to http://schemas.xmlsoap.org/soap/encoding/ or http://www.w3.org/2001/09/soap-encoding, respectively, for SOAP 1.1 and SOAP 1.2.

The array element has an additional attribute, enc:arrayType, which declares the content of the array. Array type declarations are of the form

type[size]

This is very close to Java. A array of three strings has an enc:arrayType value of xsd:string[3]; an array with 25 integers has an enc:arrayType value of xsd:integer[25]. A multi-dimensional array is of the form xsd:decimal[5][10].

The array content is encoded as a sequence of XML elements. The names of the elements are irrelevant because, for arrays, the position of the element is the accessor. Listing 11 is an array of strings.

Listing 11—An Array of Strings

<array xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xsi:type="enc:Array"
    enc:arrayType="xsd:String[3]">
  <item xsi:type="xsd:string">Board room</item>
  <item xsi:type="xsd:string">Meeting room 1</item>
  <item xsi:type="xsd:string">Meeting room 2</item>
</array>

For obvious reasons, the elements must appear in the order of the array.

Array elements are not limited to simple types; compound types are acceptable, as Listing 12, an array of Resource objects, illustrates. The Resource class was defined in Listing

Listing 12—An Array of Compound Types

<array xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
    xsi:type="enc:Array" enc:arrayType="rs:Resource[3]"
    xmlns:rs="http://www.psol.com/2001/resourceful"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <item xsi:type="rs:Resource">
    <id xsi:type="xsd:int">1</id>
    <name xsi:type="xsd:string">Board room</name>
    <description xsi:type="xsd:string">Mid-sized room,
      quality furniture</description>
  </item>
  <item xsi:type="rs:Resource">
    <id xsi:type="xsd:int">2</id>
    <name xsi:type="xsd:string">Meeting room 1</name>
    <description xsi:type="xsd:string">Mid-sized room</description>
  </item>
  <item xsi:type="rs:Resource">
    <id xsi:type="xsd:int">3</id>
    <name xsi:type="xsd:string">Meeting room 2</name>
    <description xsi:type="xsd:string">Small room</description>
  </item>
</array>

To support multidimensional arrays, SOAP uses references to arrays. A reference is an href attribute. An href attribute is a URI that points to another element in the same document. The original element is identified with an id attribute. The id attribute is of type ID as defined in XML schema and DTD.

The multidimensional array is encoded as an array of reference items pointing to the actual column data. In other words, a multidimensional array is an array whose elements point to other arrays.

Listing 13 is a multidimensional array. Note that this is a document fragment because it does not have a root element. In practice, with SOAP, it is never a problem to use document fragments since env:Envelope is the root.

Listing 13—A multidimensional array

<matrix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:enc="http://www.w3.org/2001/09/soap-encoding"
    xsi:type="enc:Array"
    enc:arrayType="xsd:int[][2]" >
  <item href="#array-1"/>
  <item href="#array-2"/>
</matrix>
<array xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:enc="http://www.w3.org/2001/09/soap-encoding"
    id="array-1"
    enc:arrayType="xsd:int[3]">
  <item>10</item>
  <item>20</item>
  <item>30</item>
</array>
<array xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:enc="http://www.w3.org/2001/09/soap-encoding"
    id="array-2"
    enc:arrayType="xsd:int[2]">
  <item>15</item>
  <item>25</item>

</array>

Because arrays can grow very large, the encoding has two optimizations for partially transmitted arrays and sparse arrays. In a partially transmitted array, not every element is sent. Typically it would be used when the recipient knows some sections of the array. The env:offset attribute specifies the zero-origin offset of the elements being transmitted in the array:

<enc:Array enc:arrayType="xsd:int[7]" enc:offset="[3]"
      xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <item>4</item>
  <item>5</item>
  <item>6</item>
</enc:Array>

Likewise, the enc:position encodes sparse arrays, in other words, arrays where most elements are null or not present:

<enc:Array enc:arrayType="xsd:string[10,10]"
      xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <item enc:position="[2,2]">Third row, third col</item>
  <item enc:position="[7,2]">Eighth row, third col</item>
</enc:Array>

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