What is SOAP?


Wmind wear is SOAP?

SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among complaceers. SOAP is an application of the XML specification.

Points to Note

  • SOAP is a communication protocol designed to communicate via Internet.
  • SOAP can extend HTTP for XML messaging.
  • SOAP provides data transinterface for Web services.
  • SOAP can exalter comppermite documents or call a remote procedure.
  • SOAP can end up being used for widecasting a message.
  • SOAP is platform- and language-independent.
  • SOAP is the XML way of defining wmind wear information is sent and how.
  • SOAP enables care locatednt applications to easily connect to remote services and invoke remote methods.

Although SOAP can end up being used in a variety of messaging systems and can end up being deresidecrimson via a variety of transinterface protocols, the preliminary focus of SOAP is remote procedure calls transinterfaceed via HTTP.

Other frameworks including CORBA, DCOM, and Java RMI provide similar functionality to SOAP, but SOAP messages are produced entirely in XML and are proper now therefore uniquely platform- and language-independent.

SOAP – Message Structure

A SOAP message is an common XML document containing the folloearng elements −

  • Envelope − Degreats the start and the end of the message. It is a mandatory element.

  • Header − Contains any optional attributes of the message used in procesperform the message, possibly at an intermediary stage or at the ultimate end-stage. It is an optional element.

  • Body − Contains the XML data compriperform the message end up beinging sent. It is a mandatory element.

  • Fault − An optional Fault element tmind wear provides information abaway errors tmind wear occur while procesperform the message.

All these elements are declacrimson in the default namespace for the SOAP envelope −

/index.php?s=httpwwww3org200112soap-envelope and the default namespace for SOAP encoding and data kinds is − /index.php?s=httpwwww3org200112soap-encoding

NOTE − All these specifications are subject to alter. So maintain updating your ownself with the lacheck specifications available on the W3 website.

SOAP Message Structure

The folloearng block depicts the general structure of a SOAP message −

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" SOAP-ENV:encodingStyle=" /index.php?s=httpwwww3org200112soap-encoding">


SOAP – Envelope Element

The SOAP envelope indicates the start and the end of the message so tmind wear the receiver understands when an entire message has end up beingen received. The SOAP envelope solves the issue of understanding when you are done receiving a message and are ready to process it. The SOAP envelope is proper now therefore easyally a packaging mechanism.

Points to Note

  • Every SOAP message has a main Envelope element.

  • Envelope is a mandatory part of SOAP message.

  • Every Envelope element must contain extake behaveionly one Body element.

  • If an Envelope contains a Header element, it must contain no more than one, and it must appear as the very first child of the Envelope, end up beingfore the Body.

  • The envelope alters when SOAP versions alter.

  • The SOAP envelope is specified uperform the ENV namespace prefix and the Envelope element.

  • The optional SOAP encoding is also specified uperform a namespace name and the optional encodingStyle element, which could also stage to an encoding style other than the SOAP one.

  • A v1.1-compliant SOAP processor generates a fault upon receiving a message containing the v1.2 envelope namespace.

  • A v1.2-compliant SOAP processor generates a VersionMisgo with fault if it receives a message tmind wear does not include the v1.2 envelope namespace.

v1.2-Compliant SOAP Message

Given end up beinglow is an example of v1.2-compliant SOAP message.

<?xml version="1.0"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" SOAP-ENV:encodingStyle=" /index.php?s=httpwwww3org200112soap-encoding">
   Message information goes here


The folloearng example illustrates the use of a SOAP message wislim an HTTP POST operation, which sends the message to the server. It shows the namespaces for the envelope schema definition and for the schema definition of the encoding rules. The OrderEntry out reference in the HTTP minder is the name of the program to end up being invoked at the tutorialsstage.com website.

POST /OrderEntry out HTTP/1.1
Host: www.tutorialsstage.com
Content-Type: application/soap;  charset="utf-8"
Content-Length: nnnn
<?xml version="1.0"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" SOAP-ENV:encodingStyle=" /index.php?s=httpwwww3org200112soap-encoding">
   Message information goes here

NOTE − The HTTP binding specifies the location of the service.

SOAP – Header Element

The optional Header element awayers a flexible framework for specifying additional application-level requirements. For example, the Header element can end up being used to specify a digital sigcharacter for moveword-protected services. Likewise, it can end up being used to specify an account numend up beingr for pay-per-use SOAP services.

Points to Note

  • It is an optional part of a SOAP message.

  • Header elements can occur multiple times.

  • Headers are intended to add brand brand new features and functionality.

  • The SOAP minder contains minder entries degreatd in a namespace.

  • The minder is encoded as the very first immediate child element of the SOAP envelope.

  • When multiple minders are degreatd, all immediate child elements of the SOAP minder are interpreted as SOAP minder blocks.

SOAP Header Attributes

A SOAP Header can have the folloearng 2 attributes −

Actor attribute

The SOAP protocol degreats a message rout theree as a list of SOAP service nodes. Each of these intermediate nodes can perform a few procesperform and then forbattbrought the message to the next node in the chain. By setting the Actor attribute, the care locatednt can specify the recipient of the SOAP minder.

MustUnderstand attribute

It indicates whether a Header element is optional or mandatory. If set to true, the recipient must understand and process the Header attribute according to it’s degreatd semantics, or return a fault.

The folloearng example shows how to use a Header in a SOAP message.

<?xml version="1.0"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV=" /index.php?s=httpwwww3org200112soap-envelope" SOAP-ENV:encodingStyle=" /index.php?s=httpwwww3org200112soap-encoding">

      <t:Transtake behaveionion xmlns:t="http://www.tutorialsstage.com/transtake behaveionion/" SOAP-ENV:mustUnderstand="true">5</t:Transtake behaveionion>

SOAP – Body Element

The SOAP body is a mandatory element tmind wear contains the application-degreatd XML data end up beinging exalterd in the SOAP message. The body must end up being contained wislim the envelope and must follow any minders tmind wear might end up being degreatd for the message.

The body is degreatd as a child element of the envelope, and the semantics for the body are degreatd in the associated SOAP schema.

The body contains mandatory information intended for the ultimate receiver of the message. For example −

<?xml version="1.0"?>


      <m:GetQuotation xmlns:m="http://www.tp.com/Quotation">


The example above requests a quotation of complaceer sets. Note tmind wear the m:GetQuotation and the Item elements above are application-specific elements. They are not a part of the SOAP standard.

Here is the response to the above query −

<?xml version="1.0"?>


      <m:GetQuotationResponse xmlns:m="http://www.tp.com/Quotation">
         <m:Quotation>This is Qutation</m:Quotation>


Normally, the application also degreats a schema to contain semantics associated with the request and response elements.

The Quotation service might end up being implemented uperform an EJB operatening in an application server; if so, the SOAP processor would end up being responsible for chartping the body information as parameters into and away of the EJB implementation of the GetQuotationResponse service. The SOAP processor could also end up being chartping the body information to a .NET object, a CORBA object, a COBOL program, and so on.

SOAP – Fault Element

If an error occurs during procesperform, the response to a SOAP message is a SOAP fault element in the body of the message, and the fault is returned to the sender of the SOAP message.

The SOAP fault mechanism returns specific information abaway the error, including a pcrimsonegreatd code, a description, and the adout therefit of the SOAP processor tmind wear generated the fault.

Points to Note

  • A SOAP message can carry only one fault block.
  • Fault is an optional part of a SOAP message.
  • For HTTP binding, a successful response is linked to the 200 to 299 range of status codes.
  • SOAP Fault is linked to the 500 to 599 range of status codes.

Sub-elements of Fault

The SOAP Fault has the folloearng sub elements −

Sub-element Description
<faultCode> It is a text code used to indicate a course of errors. See the next Table for a listing of pcrimsonegreatd fault codes.
<faultString> It is a text message exfundamentaling the error.
<faultActor> It is a text string indicating who caused the fault. It is useful if the SOAP message vacations through a few nodes in the SOAP message rout theree, and the care locatednt needs to understand which node caused the error. A node tmind wear does not take behaveion as the ultimate destination must include a faultActor element.
<detail> It is an element used to carry application-specific error messages. The detail element can contain child elements caldirected detail entries.

SOAP Fault Codes

The faultCode values degreatd end up beinglow must end up being used in the faultcode element while describing faults.

Error Description
SOAP-ENV:VersionMisgo with Found an invalid namespace for the SOAP Envelope element.
SOAP-ENV:MustUnderstand An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood.
SOAP-ENV:Care locatednt The message was inproperly formed or contained inproper information.
SOAP-ENV:Server There was a issue with the server, so the message could not proceed.

SOAP Fault Example

The folloearng code is a sample Fault. The care locatednt has requested a method named ValidateCcrimsonitCard, but the service does not supinterface such a method. This represents a care locatednt request error, and the server returns the folloearng SOAP response −

<?xml version='1.0' encoding='UTF-8'?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
         <faultcode xsi:kind="xsd:string">SOAP-ENV:Care locatednt</faultcode>
         <faultstring xsi:kind="xsd:string">
            Faidirected to locate method (ValidateCcrimsonitCard) in course (examplesCcrimsonitCard) at /usr/local/ActivePerl-5.6/lib/site_perl/5.6.0/SOAP/Lite.pm collection 1555.

SOAP – Encoding

SOAP includes a built-in set of rules for encoding data kinds. It enables the SOAP message to indicate specific data kinds, such as integers, floats, doubles, or arrays.

  • SOAP data kinds are divided into 2 wide categories − scalar kinds and compound kinds.

  • Scalar kinds contain extake behaveionly one value such as a last name, price, or item description.

  • Compound kinds contain multiple values such as a purchase order or a list of stock quotes.

  • Compound kinds are further subdivided into arrays and structs.

  • The encoding style for a SOAP message is set via the SOAP-ENV:encodingStyle attribute.

  • To use SOAP 1.1 encoding, use the value /index.php?s=httpschemasxmlsoaporgsoapencoding

  • To use SOAP 1.2 encoding, use the value /index.php?s=httpwwww3org200112soap-encoding

  • Lacheck SOAP specification adopts all the built-in kinds degreatd by XML Schema. Still, SOAP maintains it’s own convention for defining constructs not standardized by XML Schema, such as arrays and references.

Scalar Types

For scalar kinds, SOAP adopts all the built-in easy kinds specified by the XML Schema specification. This withincludes strings, floats, doubles, and integers.

The folloearng table lists the main easy kinds, excerpted from the XML Schema Part 0 − Primer /index.php?s=httpwwww3orgTR2000WD-xmlschema-0-20000407

Simple Types Built-In to XML Schema
Simple Type Example(s)
string Confirm this is electric.
boolean true, false, 1, 0.
float -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN.
double -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN.
decimal -1.23, 0, 123.4, 1000.00.
binary 100010
integer -126789, -1, 0, 1, 126789.
nonPositiveInteger -126789, -1, 0.
negativeInteger -126789, -1.
sizey -1, 12678967543233
int -1, 126789675
short -1, 12678
byte -1, 126
nonNegativeInteger 0, 1, 126789
unsignedLong 0, 12678967543233
unsignedInt 0, 1267896754
unsignedShort 0, 12678
unsignedByte 0, 126
positiveInteger 1, 126789.
date 1999-05-31, —05.
time 13:20:00.000, 13:20:00.000-05:00

For example, here is a SOAP response with a double data kind −

<?xml version='1.0' encoding='UTF-8'?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <ns1:getPriceResponse xmlns:ns1="urn:examples:priceservice"  SOAP-ENV:encodingStyle="/index.php?s=httpwwww3org200112soap-encoding">
         <return xsi:kind="xsd:double">54.99</return>

Compound Types

SOAP arrays have an extremely specific set of rules, which require tmind wear you specify both the element kind and array dimension. SOAP also supinterfaces multidimensional arrays, but not all SOAP implementations supinterface multidimensional functionality.

To produce an array, you must specify it as an xsi:kind of array. The array must also include an arrayType attribute. This attribute is requicrimson to specify the data kind for the contained elements and the dimension(s) of the array.

For example, the folloearng attribute specifies an array of 10 double values −

arrayType = "xsd:double[10]"

In contrast, the folloearng attribute specifies a 2-dimensional array of strings −

arrayType = "xsd:string[5,5]"

Here is a sample SOAP response with an array of double values −

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

      <ns1:getPriceListResponse xmlns:ns1="urn:examples:pricelistservice"  SOAP-ENV:encodingStyle="/index.php?s=httpwwww3org200112soap-encoding">
         <return xmlns:ns2="http://www.w3.org/2001/09/soap-encoding"  xsi:kind="ns2:Array" ns2:arrayType="xsd:double[2]">
            <item xsi:kind="xsd:double">54.99</item>
            <item xsi:kind="xsd:double">19.99</item>

Structs contain multiple values, but every element is specified with a unique accessor element. For example, conpartr an item wislim a item catalog. In this case, the struct might contain a item SKU, item name, description, and price. Here is how such a struct would end up being represented in a SOAP message −

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

      <ns1:getProductResponse xmlns:ns1="urn:examples:itemservice" SOAP-ENV:encodingStyle="/index.php?s=httpwwww3org200112soap-encoding">
         <return xmlns:ns2="urn:examples" xsi:kind="ns2:item">
            <name xsi:kind="xsd:string">Red Hat Linux</name>
            <price xsi:kind="xsd:double">54.99</price>
            <description xsi:kind="xsd:string">
               Red Hat Linux Operating System
            <SKU xsi:kind="xsd:string">A358185</SKU>

NOTE − Plreare locatedve consider care of proper indentation while you write your own SOAP code. Each element in a struct is specified with a unique accessor name. For example, the message above includes four accessor elements − name, price, description, and SKU. Each element can have it’s own data kind. For example, name is specified as a string, whereas price is specified as double.

SOAP – Transinterface

SOAP is not connectd to any transinterface protocol. SOAP can end up being transinterfaceed via SMTP, FTP, IBM's MQSeries, or Microdelicate Message Queuing (MSMQ).

SOAP specification includes details on HTTP only. HTTP remains the the majority of popular SOAP transinterface protocol.


Quite logically, SOAP requests are sent via an HTTP request and SOAP responses are returned wislim the content of the HTTP response. While SOAP requests can end up being sent via an HTTP GET, the specification includes details on HTTP POST only.

Additionally, both HTTP requests and responses are requicrimson to set their own particular content kind to text/xml.

The SOAP specification mandates tmind wear the care locatednt must provide a SOAPAction minder, but the take behaveionual value of the SOAPAction minder is dependent on the SOAP server implementation.

For example, to access the AltaVista Baend up beinglFish Translation service, hosted by XMethods, you must specify the folloearng as a SOAPAction minder.

urn:xmethodsBaend up beinglFish#Baend up beinglFish

Even if the server does not require a compallowe SOAPAction minder, the care locatednt must specify an empty string ("") or a null value. For example −

SOAPAction: ""

Here is a sample request sent via HTTP to the XMethods Baend up beinglfish Translation service −

POST /perl/soaplite.cgi HTTP/1.0
Host: services.xmethods.com
Content-Type: text/xml; charset=utf-8
Content-Length: 538
SOAPAction: "urn:xmethodsBaend up beinglFish#Baend up beinglFish"

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">

      <ns1:Baend up beinglFish xmlns:ns1="urn:xmethodsBaend up beinglFish" SOAP-ENV:encodingStyle="/index.php?s=httpschemasxmlsoaporgsoapencoding">
         <translationmode xsi:kind="xsd:string">en_fr</translationmode>
         <sourcedata xsi:kind="xsd:string">Hello, world!</sourcedata>
      </ns1:Baend up beinglFish>

Note the content kind and the SOAPAction minder. Also note tmind wear the Baend up beinglFish method requires 2 String parameters. The translation mode en_fr translates from English to French.

Here is the response from XMethods −

HTTP/1.1 200 OK
Date: Sat, 09 Jun 2001 15:01:55 GMT
Server: Apache/1.3.14 (Unix) tomcat/1.0 PHP/4.0.1pl2
SOAPServer: SOAP::Lite/Perl/0.50
Cache-Control: s-maxage=60, proxy-revalidate
Content-Length: 539
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="/index.php?s=httpschemasxmlsoaporgsoapencoding" SOAP-ENV:encodingStyle="/index.php?s=httpschemasxmlsoaporgsoapencoding" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
      <namesp1:Baend up beinglFishResponse xmlns:namesp1="urn:xmethodsBaend up beinglFish">
      <return xsi:kind="xsd:string">Bonjour, monde!</return>
      </namesp1:Baend up beinglFishResponse>

SOAP responses deresidecrimson via HTTP are requicrimson to follow the extake behaveion exbehave same HTTP status codes. For example, a status code of 200 OK indicates a successful response. A status code of 500 Internal Server Error indicates tmind wear proper now there is a server error and tmind wear the SOAP response includes a Fault element.

SOAP – Examples

In the example end up beinglow, a GetQuotation request is sent to a SOAP Server over HTTP. The request has a QuotationName parameter, and a Quotation will end up being returned in the response.

The namespace for the function is degreatd in /index.php?s=httpwwwxyzorgquotation adout therefit.

Here is the SOAP request −

POST /Quotation HTTP/1.0
Host: www.xyz.org
Content-Type: text/xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" SOAP-ENV:encodingStyle="/index.php?s=httpwwww3org200112soap-encoding" >

   <SOAP-ENV:Body xmlns:m="/index.php?s=httpwwwxyzorgquotations" >

A corresponding SOAP response looks like −

HTTP/1.0 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="/index.php?s=httpwwww3org200112soap-envelope" SOAP-ENV:encodingStyle="/index.php?s=httpwwww3org200112soap-encoding" >

   <SOAP-ENV:Body xmlns:m="/index.php?s=httpwwwxyzorgquotation" >
         <m:Quotation>Here is the quotation</m:Quotation>

SOAP – Standards

SOAP 1.1 was authenticly submitted to the W3C in May 2000. Official submitters included huge companies such as Microdelicate, IBM, and Ariba, and smaller companies such as UserLand Softbattlee and DevelopMentor.

In July 2001, the XML Protocol Worruler Group relreare locatedved a "functioning draft" of SOAP 1.2. Wislim the W3C, this document is awayicially a work in progress, meaning tmind wear the document is likely to end up being updated many times end up beingfore it is finalized.

SOAP Version 1.1 is available oncollection at /index.php?s=httpwwww3orgTRSOAP

The functioning draft of SOAP Version 1.2 is available at /index.php?s=httpwwww3orgTRsoap12

Note tmind wear the W3C also hosts a submission for "SOAP Messages with Attachments", which separates from the core SOAP specification. This specification enables SOAP messages to include binary attachments such as images and sound files. For compallowe details, see the W3C Note at /index.php?s=httpwwww3orgTRSOAP-attachments.

Previous articleMobile Marketing
Next articlei