Web Services

SOAP IN Web services

SOAP Tutorial

SOAP (Simple Object Access Protocol)
Previous Home Next

Introduction

SOAP is a W3C recommendation. SOAP is an XML-based protocol for exchanging information between computers. SOAP is acronym for Simple Object Access Protocol. Soap provide data transport layer for web services which designed for communication through internet means we can say that SOAP is a communication protocol. It is a platform independent and can be used for broadcasting a message. SOAP is language independent and it can be exchange complete documents. SOAP enables client applications to easily connect to remote services and invoke remote methods. Other frameworks like CORBA, DCOM, and Java RMI, provide similar functionality but SOAP messages are written in XML.

Why SOAP

To develop any application over  internet, communication is necessary. Today's applications communicate using Remote Procedure Calls (RPC) but RPC represents security problem; firewalls and proxy servers will block this kind of traffic. The communication establish between objects, like DCOM and CORBA, but one problem occurring that  HTTP was not designed for that types communications. A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP provides facility to communicate between applications running on different operating systems, with different technologies and programming languages.

A SOAP message is a XML document containing the following elements:-
  • Envelope: (Mandatory) defines the start and the end of the message.
  • Header: (Optional) Contains any optional attributes of the message used in processing the message, either at an intermediary point or at the ultimate end point.
  • Body: (Mandatory) Contains the XML data comprising the message being sent.
  • Fault: (Optional) An optional Fault element that provides information about errors that occurred while processing the message.
Syntax for soap:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap=""
soap:encodingStyle="">
<soap:Header>
...
</soap:Header>
<soap:Body>
...
  <soap:Fault>
  ...
  </soap:Fault>
</soap:Body>
</soap:Envelope>

SOAP Envelope Element

The SOAP envelope indicates the start and the end of the message. SOAP envelope as a packaging mechanism and its solves the problem to knowing when receiving a message with message are ready to process it.


<?xml version="1.0"?>
<soap:Envelope
xmlns:soap=""
soap:encodingStyle="">
  ...
  Information Message
  ...
</soap:Envelope>

Some Features are:

  • Envelope element is mandatory part of SOAP message and SOAP message has a root Envelop element
  • Soap Message Envelope element  contained exactly one Body element. It is necessary.
  • When Envelope contains a Header element then  it must contain no more than one. In that case it must appear as the first child of the Envelope, before the Body.
  • SOAP versions change as well as envelop be changed.
  • The optional SOAP encoding is also specified using a namespace name and the optional encodingStyle element, which could also point to an encoding style other than the SOAP one.
SOAP Header Element

The Header element can be used to specify a digital signature for password-protected services; likewise, it can be used to specify an account number for pay-per-use SOAP services. Header elements are optional part of SOAP messages and it can occur multiple times. Headers are intended to add new features and functionality and it is the first immediate child element of the SOAP envelope. If in a SOAP message more than one header is defined then all immediate child elements of the SOAP header are interpreted as SOAP header blocks.

<soap:Header>
  <m:Trans xmlns:m="http://www.r4r.co.in/"
  soap:mustUnderstand="1">....
  </m:Trans>
</soap:Header>

SOAP Header element can have following two attributes:

  • Actor attribute: The SOAP protocol defines a message path as a list of SOAP service nodes. Each of these intermediate nodes can perform some processing and then forward the message to the next node in the chain. By setting the Actor attribute, the client can specify the recipient of the SOAP header.
  • MustUnderstand attribute: This attribute indicate that a Header element is optional or mandatory.
SOAP Body Element

The SOAP body is a mandatory element which contains the application-defined XML data being exchanged in the SOAP message. The body must be contained within the envelope and must follow any headers that might be defined for the message. The body is defined as a child element of the envelope, and the semantics for the body are defined in the associated SOAP schema.

<soap:Body>
  <m:GetPrice xmlns:m="http://www.r4r.co.in/">
    <m:Item>Tables</m:Item>
  </m:GetPrice>
</soap:Body>
SOAP Fault Element

SOAP fault element is in the body of the message when an error occurs during processing the response to a SOAP message. The fault is returned to the sender of the SOAP message. Its use the fault mechanism to return specific information about error. It is important to know that SOAP message can carry only one fault block It is the optional part of SOAP message.

The SOAP Fault element has the following sub elements

Sub Element Description
<faultCode> A text code used to indicate and identify the a class of errors.
<faultString> Explanation of the fault in human readable format.
<faultActor> A text string indicating that who caused the fault, a node that does not act as the ultimate destination must include a faultActor element.
<detail> An element used to carry application-specific error messages. The detail element can contain child elements, called detail entries

The SOAP Fault Codes

Error Description
VersionMismatch Found an invalid namespace for the SOAP Envelope element
MustUnderstand An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood
Client The message was incorrectly formed or contained incorrect information
:Server There was a problem with the server so the message could not proceed
SOAP Encoding

SOAP includes a built-in set of rules for encoding data types. This enables the SOAP message to indicate specific data types, such as integers, floats, doubles, or arrays. SOAP data types are divided into two categories:

  1. Scalar Types:Scalar types contain exactly one value for example last name, price.
  2. Simple Type Example
    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.00x
    decimal 100010
    binary -1.23, 0, 123.4, 1000.00x
    integer -126789, -1, 0
    negativeInteger -1, 12678967543233
    long -1.23, 0, 123.4, 1000.00x
    int -1, 126789675
    short -1, 12678
    byte -1, 126
    nonNegativeInteger 0, 1, 126789
    unsignedLong 0, 12678967543233
    unsignedInt 0, 1267896754
    unsignedShort 0, 12678
    unsignedBytee 0, 126
    positiveInteger 1, 126789
    date 1999-05-31, ---05
    time 13:20:00.000, 13:20:00.000-05:00
  3. Compound Types:
  4. Compound types contain multiple values, such as a purchase order or a list of stock quotes. Compound types are further subdivided into arrays and structs.

     

    Array: SOAP arrays have a very specific set of rules, means you must require to specified both the element type and  size of array. It also supports multidimensional arrays. One thing is important to know that all SOAP implementations not support multidimensional functionality. To create an array, you must specify it:

    1. Type of Array.
    2. The array must also include an arrayType attribute. This attribute is required to specify the data type for the contained elements and the dimension of the array.

    Structs: Structs contain multiple values, but each element is specified with a unique accessor element.

    SOAP and HTTP
    • SOAP is not tied to any one transport protocol. SOAP can be transported via SMTP, FTP or Microsoft Message Queuing (MSMQ). SOAP used HTTP request to send SOAP request. SOAP responses are returned within the content of the HTTP response. Means SOAP specification includes details on HTTP only.

    • HTTP requests and HTTP responses both are required to set their content type to text/xml. The SOAP specification mandates that the client must provide a SOAPAction header, but the actual value of the SOAPAction header is dependent on the SOAP server implementation.

    Previous Home Next

    Tolal:0 Click:

    Show All Comments

    Did not find what you were looking for leave your name and message. We will revert within 24 hours
    Name:
    eMail:
    Comment / Feedback: