KEMBAR78
SOAP Protocol in Web Services | PDF | Soap | Web Service
0% found this document useful (0 votes)
28 views42 pages

SOAP Protocol in Web Services

Uploaded by

2313323037015
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views42 pages

SOAP Protocol in Web Services

Uploaded by

2313323037015
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

SOAP (Simple Object Access Protocol) is a protocol used in web services to enable

communication between different applications over a network. It defines a standardized way


for applications to exchange structured information using XML (eXtensible Markup
Language). SOAP is particularly popular for enabling web services to interact across
different platforms and programming languages in a secure and reliable manner.

Key Features of SOAP in Web Services:

1. XML-Based:
○ SOAP messages are formatted in XML, which makes them
platform-independent. This allows different systems, regardless of their
underlying technology or programming language, to communicate seamlessly.
2. Transport-Independent:
○ SOAP can be transported over a variety of protocols, such as HTTP, SMTP,
TCP, and more. However, HTTP is the most commonly used transport
protocol for SOAP in web services.
○ Since it is transport-independent, SOAP can be used in a wide variety of
network environments, including those that use email or message queues.
3. Envelope Structure:
○ SOAP messages are contained in an envelope, which defines the structure of
the message and contains important metadata about the message. The
envelope is the root element of a SOAP message and consists of two main
parts:
1. Header (optional): Contains information about the message itself, such
as security tokens, routing data, or transaction information.
2. Body: Contains the actual message or call (request/response) in XML
format.

Example SOAP message structure:


<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<!-- Optional metadata, like authentication details -->
</soap:Header>
<soap:Body>
<!-- The actual request or response data in XML format -->
</soap:Body>
</soap:Envelope>

4. Standardized Messaging:
○ SOAP defines a set of rules for sending and receiving messages between
services, including how to format requests and responses. This standardization
ensures that services can communicate without ambiguity.
5. Extensibility:
○ SOAP is highly extensible and allows for adding extra features like security,
transaction management, and reliability. These extensions are often defined in
the SOAP header.
○ WS-Security is a standard that adds security features to SOAP messages, such
as digital signatures and encryption.
6. Error Handling:
○ SOAP includes a mechanism for error handling via the Fault element. This
element is included in the body of the SOAP message when there is an error in
processing a request.
○ The Fault element provides standardized error codes and messages to help in
diagnosing and handling issues.
7. Interoperability:
○ SOAP is designed to be interoperable between different platforms. It works
well with the WSDL (Web Services Description Language), which is used to
describe the operations offered by a web service. Using SOAP and WSDL
together enables automatic generation of client and server stubs, making it
easier for developers to consume services.

Example of a SOAP Message:

SOAP Request (Example for a weather service):

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<!-- Optional header information like authentication tokens -->
</soap:Header>
<soap:Body>
<GetWeather xmlns="http://www.example.com/weather">
<City>New York</City>
</GetWeather>
</soap:Body>
</soap:Envelope>

SOAP Response:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<GetWeatherResponse xmlns="http://www.example.com/weather">
<Temperature>15</Temperature>
<Condition>Sunny</Condition>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>

Advantages of SOAP in Web Services:

1. Platform and Language Independence:


○ Since SOAP uses XML as its message format, it can work across different
platforms and languages (e.g., Java, .NET, PHP) without compatibility issues.
2. Reliable Messaging:
○ SOAP can guarantee the delivery of messages (with protocols like
WS-ReliableMessaging), making it ideal for scenarios where communication
reliability is essential, such as financial transactions.
3. Built-in Error Handling:
○ The standardized fault structure allows SOAP to handle errors in a uniform
way, making troubleshooting easier.
4. Extensibility with Web Service Standards:
○ SOAP supports various extensions, including WS-Security for message-level
security, WS-AtomicTransaction for transactions, and WS-ReliableMessaging
for ensuring that messages are delivered reliably.
5. Works Well with Firewalls:
○ Since SOAP can use HTTP as a transport protocol, it easily passes through
most firewalls without requiring special configuration.

Disadvantages of SOAP:

1. Complexity:
○ SOAP can be more complex to implement than simpler alternatives like REST
because of its reliance on XML, headers, and detailed message structures.
2. Performance Overhead:
○ SOAP messages are typically larger than REST messages because they are
XML-based and include additional metadata (e.g., headers), which increases
the size of the message and may slow down transmission over the network.
3. Tightly Coupled:
○ SOAP-based web services are often more tightly coupled with the client
because of the reliance on WSDL to define the service interface. This can lead
to difficulties in versioning an d maintaining services over time.

SOAP vs. REST (Simple Comparison):


1.SOAP Message Exchange Model

SOAP (Simple Object Access Protocol) Message Exchange Model defines how messages are
transmitted between a client and a server in a web service environment. It outlines the process of
sending and receiving SOAP messages using a request-response or one-way communication pattern,
which is crucial for distributed computing.

Key Elements of the SOAP Message Exchange Model:

1. SOAP Nodes:
- SOAP nodes are entities that process SOAP messages. There are typically three types:
Initial Sender: The node that originates the SOAP message (usually a client).
Intermediaries: Nodes that receive the message and forward it to the next node.
Ultimate Receiver: The final node that processes the message (usually the server).

2. Message Path:
- The path that the SOAP message takes from the initial sender, through intermediaries, to the
ultimate receiver.
- The message may pass through multiple intermediaries for various processing tasks such as
logging, security checks, or transformations before reaching the final destination.

3. SOAP Messages:
The communication is done using SOAP messages, which are XML-based envelopes. These contain
a Header (optional) and a Body (mandatory), allowing information to be exchanged between nodes.

4. Message Exchange Patterns (MEPs):


Request-Response:
- In this common pattern, the client sends a request to the server, and the server responds with a
message. This two-way communication is synchronous.
One-Way:
- In this pattern, the client sends a message to the server without expecting a response. This is used
for asynchronous processing, such as logging or notifications.
Notification:
- The server sends a message to the client without the client initiating the request. This is another
form of one-way communication.
Solicit-Response:
- The server initiates the request and the client sends back the response.

5. SOAP Intermediaries:
These are optional processing nodes that act on the SOAP headers. They can modify, add, or remove
headers for purposes like encryption, logging, or routing but do not change the body of the message.

6. Message Processing:
Each SOAP node, including intermediaries and the ultimate receiver, must process the message
according to the SOAP processing model. The ultimate receiver is responsible for interpreting the
SOAP body and acting on it, while intermediaries handle only the header information.

7. SOAP Faults:
- When a SOAP message cannot be processed correctly, a SOAP Fault is generated. This is a special
message that informs the sender of an error, specifying the cause of the failure (e.g., incorrect data,
security violation).

Example of Request-Response Pattern:

Client (Initial Sender): Sends a SOAP request (e.g., asking for weather data).
Server (Ultimate Receiver): Receives the request, processes it, and sends back a response with the
requested weather data.
Intermediaries (Optional): If intermediaries are involved, they might log the request or encrypt parts
of the message before it reaches the server.

Significance:
The SOAP message exchange model ensures interoperability and flexibility by defining how nodes
communicate in distributed systems. It allows services to be loosely coupled, supports message
routing, and provides fault handling mechanisms.

In conclusion, the SOAP message exchange model provides a robust, extensible framework for
exchanging information in a distributed web services environment, enabling seamless communication
between diverse systems.

SOAP Message Exchange Model

SOAP messages are always synchronous. They can implement Request/Response synchronous
messages with the response having the output parameters returned in another SOAP document to the
sender.SOAP supports HTTP-POST and HTTP-GET formats. PeopleSoft supports only HTTP, using
the Integration Gateway.Processing the message requires validation of the mandatory sections of the
SOAP XML document and understanding SOAP namespaces.

2.SOAP Messaging and its Key Features:


SOAP (Simple Object Access Protocol) messaging refers to the process of exchanging information
between a client and a server using SOAP messages in a web services environment. These messages
are XML-based, enabling platform-independent communication over a network, typically using
standard internet protocols such as HTTP or SMTP.

A SOAP message is a well-structured XML document that consists of a SOAP envelope containing
optional headers and a body. It supports communication between various applications, regardless of
the operating system, programming language, or platform.

Key Features of SOAP Messaging:

1. Platform and Language Independence:


○ SOAP messages are based on XML, which is a platform-neutral and
language-agnostic format. This allows SOAP-based web services to communicate
between different systems (e.g., Java, .NET, Python) seamlessly.
2. Extensibility:
○ SOAP is highly extensible. It allows for additional information to be included in
headers, enabling support for features like security (WS-Security), transactions, and
message routing without affecting the core message content.
3. Standardized Structure:
○ SOAP defines a strict message format consisting of:
■ Envelope: The root element that defines the start and end of the message.
■ Header (optional): Contains metadata for processing the message, such as
security, routing, or transaction information.
■ Body: The core part of the message containing the actual data or payload,
which is processed by the recipient.
■ Fault (optional): Used to communicate errors during message processing.
4. Support for Different Transport Protocols:
○ While HTTP is the most commonly used transport protocol for SOAP messaging,
SOAP can also be transported over other protocols like SMTP, JMS, FTP, and more.
This provides flexibility in choosing the right communication mechanism for
different use cases.
5. Security:
○ SOAP supports robust security mechanisms. WS-Security standards can be used in
conjunction with SOAP to provide message integrity, confidentiality, and
authentication. This ensures that sensitive information can be securely transmitted
between web services.
6. Reliability:
○ SOAP messaging is designed to be reliable. Through features like fault handling
(using the SOAP Fault element), SOAP provides mechanisms to detect and handle
errors. Additionally, SOAP can work with transport protocols that support reliable
messaging, ensuring that messages are delivered accurately and in order.
7. Loose Coupling:
○ SOAP allows for loose coupling between clients and services. The client doesn't need
to know about the service's internal implementation, only about the WSDL (Web
Services Description Language) that defines the service interface and the SOAP
message format.
8. Intermediary Support:
○ SOAP messaging allows for the use of intermediaries, which are nodes that can
process a message before it reaches its final destination. This enables functionalities
such as message logging, security processing, or transformation (for example,
encryption) at various points in the message flow.
9. Statefulness:
○ While most web services operate in a stateless manner, SOAP messaging can support
stateful operations. It allows the server to manage and maintain state across multiple
SOAP message exchanges, which is beneficial for applications that require session
management.
10. Well-Defined Error Handling:
○ SOAP has a structured error-handling mechanism through the use of the SOAP Fault
element. This allows a service to communicate detailed error information back to the
client, such as invalid requests, processing errors, or security violations.

Example of SOAP Messaging:


A typical SOAP message for requesting weather data may look like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ws="http://www.example.org/weather">
<soap:Header>
<!-- Header information (e.g., authentication or transaction details) -->
</soap:Header>
<soap:Body>
<ws:GetWeather>
<ws:City>New York</ws:City>
</ws:GetWeather>
</soap:Body>
</soap:Envelope>

In this example:

● The Envelope contains the entire message.


● The Body holds the actual request to get weather data for New York.
● The Header can contain additional data like security credentials or routing information.

Advantages of SOAP Messaging:

● Interoperability: Can work across various platforms and technologies.


● Security: Supports advanced security standards (WS-Security).
● Reliability: Can work with reliable transport protocols, and provides error handling via faults.
● Extensibility: Custom headers allow for features like transactions and routing.
● Transport Agnostic: Can use multiple transport protocols, not just HTTP.

In summary, SOAP messaging is a versatile and secure way of exchanging structured data across
different platforms and environments, making it a key protocol for enterprise-level web services.

3.SOAP MESSAGE STRUCTURE:

A SOAP message is encoded as an XML document, consisting of an <Envelope> element,


which contains an optional <Header> element, and a mandatory <Body> element. The
<Fault> element, contained in <Body>, is used for reporting errors.

The SOAP envelope


<Envelope> is the root element in every SOAP message, and contains two child elements, an
optional <Header> element, and a mandatory <Body> element.
The SOAP header
<Header> is an optional subelement of the SOAP envelope, and is used to pass
application-related information that is to be processed by SOAP nodes along the message
path.
The SOAP body
<Body> is a mandatory subelement of the SOAP envelope, which contains information
intended for the ultimate recipient of the message.
The SOAP fault
<Fault> is a subelement of the SOAP body, which is used for reporting errors.

XML elements in <Header> and <Body> are defined by the applications that make use of
them, although the SOAP specification imposes some constraints on their structure. The
following diagram shows the structure of a SOAP message.
A SOAP (Simple Object Access Protocol) message is a protocol for exchanging structured
information in web services, using XML. It’s designed to be platform-independent and
language-neutral, enabling communication between different systems. A SOAP message
consists of four main parts:

Structure of a SOAP Message

A typical SOAP message is an XML document, which is structured as follows:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header> ... </soap:Header>
<soap:Body> ... </soap:Body>
<soap:Fault> ... </soap:Fault>
</soap:Envelope>

Elements of a SOAP Message

1. SOAP Envelope
○ Description: This is the root element of a SOAP message, and it defines the
XML document as a SOAP message. The Envelope element contains the
Header and Body elements.
○ Purpose: It defines the boundaries of the message and ensures that the SOAP
message is understood by the recipient.
2. SOAP Header (Optional)
○ Description: This optional element contains metadata about the SOAP
message, such as authentication, transaction control, or session data.
○ Purpose: The header can contain information that must be processed by
intermediaries along the message path before reaching the final destination.
○ Example:

<soap:Header>
<auth:Authentication xmlns:auth="http://example.com/auth">
<auth:Token>abc123</auth:Token>
</auth:Authentication>
</soap:Header>

SOAP Body

● Description: The body is the main part of the message. It contains the actual message
that is being transmitted between systems (request or response). The content inside
the body is typically application-specific information.
● Purpose: It carries the message payload (e.g., a request to a web service or the
response).
● Example:

<soap:Body>
<m:GetTemperature xmlns:m="http://www.example.org/weather">
<m:City>New York</m:City>
</m:GetTemperature>
</soap:Body>

SOAP Fault (Optional)

● Description: The Fault element provides information about any error that occurs
during the processing of the message. If the message processing fails, the Fault
element is included in the Body to communicate the error details.
● Purpose: Used to report errors, such as client mistakes (incorrect parameters) or
server issues (service unavailability).
● Example:

<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Invalid City Name</faultstring>
</soap:Fault>

Example of Complete code:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<auth:Authentication xmlns:auth="http://example.com/auth">
<auth:Token>abc123</auth:Token>
</auth:Authentication>
</soap:Header>
<soap:Body>
<m:GetTemperature xmlns:m="http://www.example.org/weather">
<m:City>New York</m:City>
</m:GetTemperature>
</soap:Body>
</soap:Envelope>

This SOAP message is requesting the temperature for the city of New York, with the
authentication token provided in the header. If something goes wrong, a Fault element would
be included in the response.

Tutorials point link

4. SOAP Encoding

SOAP encoding defines how data types (both simple and complex) are serialized into XML
for transmission in a SOAP message. This serialization allows the message to be understood
and reconstructed by different systems, enabling interoperability between web services.

SOAP encoding is governed by the SOAP encoding rules, specified in the SOAP
specification. It ensures that various data structures (like numbers, strings, arrays, and
objects) can be represented in a standardized XML format, so they can be exchanged between
different platforms and technologies.

Key Aspects of SOAP Encoding:

1. Namespace Declaration:
○ SOAP encoding is associated with a specific namespace:
http://schemas.xmlsoap.org/soap/encoding/.
○ Example of how it's declared

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

Data Serialization:

● SOAP uses XML Schema (XSD) to describe the types and structure of data. The
xsi:type attribute defines the data type of elements in the SOAP message.
● Example (string data type with encoding)

<soap:Body>
<name xsi:type="xsd:string">John Doe</name>
</soap:Body>

Simple and Compound Data Types in SOAP Encoding

SOAP defines two broad categories of data types:


1. Simple Data Types: Primitive data types like int, float, string, etc.
2. Compound Data Types: Complex data types that group multiple values together,
such as arrays or structured objects.

1. Simple Data Types

Simple data types are basic, primitive types like integers, floating-point numbers, strings,
and boolean values. SOAP relies on XML Schema definitions (xsd: namespace) for defining
these data types.

Common Simple Data Types:

1. Xsd : Represents a string of characters.

Example:

<name xsi:type="xsd:string">Alice</name>

2. Xsd : Represents an integer value.

Example:

<age xsi:type="xsd:int">30</age>

3. Xsd : Represents a floating-point number.

Example:

<temperature xsi:type="xsd:float">98.6</temperature>

4. Xsd : Represents a boolean value (true or false).

Example:

<isMarried xsi:type="xsd:boolean">false</isMarried>

5. Xsd : Represents a date in the format YYYY-MM-DD.

Example:

<dob xsi:type="xsd:date">1990-05-15</dob>
Example of SOAP Message with Simple Data Types:

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

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>

<person>

<name xsi:type="xsd:string">Alice</name>

<age xsi:type="xsd:int">30</age>

<isMarried xsi:type="xsd:boolean">false</isMarried>

</person>

</soap:Body>

</soap:Envelope>

In this example:

● name is a string (xsd:string).


● age is an integer (xsd:int).
● isMarried is a boolean (xsd:boolean).

2. Compound Data Types

Compound data types are more complex structures that can contain multiple values or
fields. SOAP encoding supports two common types of compound data types:

● Arrays: Ordered collections of items, all of which are of the same data type.
● Structures: Groupings of multiple named fields, which can be of different data types.

2.1. Arrays

An array is an ordered list of elements, all of which have the same data type. SOAP
encoding represents arrays with attributes such as arrayType to specify the type and length of
the array.

Example (SOAP Array):


<soap:Body>

<numbers xsi:type="soap:Array" soap:arrayType="xsd:int[3]">

<item>10</item>

<item>20</item>

<item>30</item>

</numbers>

</soap:Body>

In this example:

● numbers is an array of integers (xsd:int).


● The array contains 3 elements: 10, 20, and 30.

2.2. Structs (Complex Types)

A struct (or complex type) is a data structure that groups multiple fields, which can each
have a different type. SOAP encoding serializes structs as XML elements, with each field
represented as an individual child element.

Example (SOAP Struct):

<soap:Body>

<person xsi:type="soap:Struct">

<name xsi:type="xsd:string">John Doe</name>

<age xsi:type="xsd:int">35</age>

<email xsi:type="xsd:string">john.doe@example.com</email>

</person>

</soap:Body>

In this example:
● person is a complex structure (SOAP struct).
● It has three fields: name (string), age (integer), and email (string).

SOAP Encoding and xsi

Attribute

● The xsi:type attribute is used in SOAP encoding to define the specific data type of
each element.
● The types are based on XML Schema (xsd:) types for simple data, or SOAP-specific
types like Array and Struct for compound data.
● The encodingStyle attribute in the SOAP envelope indicates that SOAP encoding is
being used.

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

soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

...

</soap:Envelope>

Full Example with Both Simple and Compound Data Types:Consider a


scenario where a web service request includes personal details (structured data) and a
list of favorite numbers (array). Here's how SOAP encoding handles the data:

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

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<soap:Body>

<person xsi:type="soap:Struct">

<name xsi:type="xsd:string">Alice</name>
<age xsi:type="xsd:int">30</age>

<isMarried xsi:type="xsd:boolean">false</isMarried>

<favoriteNumbers xsi:type="soap:Array" soap:arrayType="xsd:int[3]">

<item>7</item>

<item>11</item>

<item>42</item>

</favoriteNumbers>

</person>

</soap:Body>

</soap:Envelope>

In this example:

● The person struct contains fields like name, age, and isMarried (simple types).
● favoriteNumbers is an array of integers (compound type).

Summary:

● SOAP encoding defines how data is serialized into XML for transmission.
● Simple data types include primitive types like strings, integers, floats, and booleans,
based on XML Schema.
● Compound data types include arrays and structs, which allow for more complex data
structures to be transmitted.

5.

SOAP Communication refers to how SOAP (Simple Object Access Protocol) facilitates the
exchange of structured information between web services and client applications over a
network. SOAP communication involves sending and receiving SOAP messages, which are
XML-based, via a transport protocol like HTTP, SMTP, or TCP. SOAP enables different
applications to communicate across platforms, programming languages, and networks by
adhering to a standardized format.
Components of SOAP Communication:

1. SOAP Message:
○ The core of SOAP communication is the SOAP message. This message is an
XML-based request or response sent between a client and a web service.
○ Each SOAP message has a defined structure that includes:
■ Envelope: Defines the start and end of the message.
■ Header (optional): Contains metadata, such as security tokens, routing
information, or transaction controls.
■ Body: Contains the actual data being exchanged, such as function
parameters (in a request) or results (in a response).
■ Fault (optional): Contains error information when something goes
wrong during the processing of a message.
2. Transport Protocols:
○ SOAP is protocol-independent and can be used over various transport
protocols like:
■ HTTP/HTTPS: The most commonly used transport protocol for
SOAP communication. It allows SOAP messages to be sent over the
web.
■ SMTP: SOAP can be used with email-based transport.
■ JMS: Java Message Service can also be used for SOAP message
exchange.
■ TCP: SOAP messages can also be exchanged directly over TCP/IP.
3. Synchronous and Asynchronous Communication:
○ Synchronous Communication: In a typical HTTP-based SOAP
communication, the client sends a request to the server and waits for the
response in the same session.
○ Asynchronous Communication: With SMTP or JMS, the SOAP message is
sent, and the response may come later, allowing the client to process other
tasks while waiting for the response.

How SOAP Communication Works (Step-by-Step):

1. Client Sends a Request:


○ The client creates a SOAP request message. This message contains the
necessary data, such as the operation to be performed (e.g., getting weather
information) and its parameters.
○ The message is formatted in XML and wrapped in a SOAP envelope.
○ The client sends the request to the server over a transport protocol like HTTP
or HTTPS.
Example SOAP Request:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

<soap:Header/>

<soap:Body>

<GetWeather xmlns="http://www.example.com/weather">

<City>New York</City>

</GetWeather>

</soap:Body>

</soap:Envelope>

2. Server Receives and Processes the Request:


○ The web service receives the SOAP request and processes it.
○ The service executes the requested operation (e.g., retrieving weather data for
"New York") using the parameters provided by the client.
3. Server Sends a Response:
○ After processing the request, the server sends a SOAP response back to the
client.
○ The response message is also structured in XML and wrapped in a SOAP
envelope.

Example SOAP Response:


xml
Copy code
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

<soap:Body>

<GetWeatherResponse xmlns="http://www.example.com/weather">

<City>New York</City>

<Temperature>15</Temperature>

<Condition>Sunny</Condition>

</GetWeatherResponse>

</soap:Body>

</soap:Envelope>
4. Client Receives and Interprets the Response:
○ The client receives the SOAP response and extracts the necessary data from
the message (e.g., "Temperature" and "Condition").
○ The client can then display the data or perform further processing.

Detailed Structure of SOAP Message:

1. SOAP Envelope:
○ The root element of every SOAP message, defining the boundaries of the
message.

Example:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

2. SOAP Header (Optional):


○ The header contains metadata about the SOAP message, such as security
tokens, transaction details, or routing instructions.
○ It can be used to implement features like WS-Security (for signing or
encrypting messages), WS-ReliableMessaging (for ensuring message
delivery), etc.

Example:
<soap:Header>

<Security>

<!-- Authentication tokens or credentials -->

</Security>

</soap:Header>

3. SOAP Body:
○ The body contains the actual payload (data), which could be a request or a
response, depending on the context.

Example:
<soap:Body>

<GetWeather>

<City>New York</City>

</GetWeather>
</soap:Body>

4. SOAP Fault (Optional):


○ If an error occurs during processing, the SOAP Fault element is used to
communicate error information back to the client.
○ The fault element contains details such as fault codes and error messages.

Example:
<soap:Body>

<soap:Fault>

<faultcode>Client</faultcode>

<faultstring>Invalid city name</faultstring>

</soap:Fault>

</soap:Body>

Transport and Protocols Used in SOAP Communication:

1. SOAP Over HTTP/HTTPS:


○ HTTP is the most common transport protocol for SOAP messages. The
request and response messages are transmitted over HTTP.
○ HTTPS is used when additional security (e.g., SSL/TLS encryption) is
required for transmitting sensitive data.
2. Example of SOAP Over HTTP:

HTTP Request (POST):


POST /weather HTTP/1.1

Host: www.example.com

Content-Type: text/xml; charset=utf-8

Content-Length: length

<soap:Envelope>

<!-- SOAP Message -->

</soap:Envelope>
HTTP Response:

HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8

Content-Length: length

<soap:Envelope>

<!-- SOAP Response -->

</soap:Envelope>

3. SOAP Over SMTP:


○ SOAP messages can be sent as email attachments via SMTP. The request is
sent as an email, and the response is returned similarly.
○ This method is used for asynchronous messaging.
4. SOAP Over JMS (Java Message Service):
○ SOAP can also be transported over messaging protocols like JMS, which is
often used in enterprise environments for reliable, asynchronous messaging.
○ In this case, SOAP requests are sent as JMS messages, and responses are
handled through message queues.

Advantages of SOAP Communication:

1. Platform and Language Independence:


○ Because SOAP uses XML, it is platform and language-independent.
Applications written in different programming languages can communicate
using SOAP.
2. Reliable Communication:
○ SOAP can be extended with protocols like WS-ReliableMessaging to ensure
that messages are delivered reliably, even in the case of network failures.
3. Security:
○ SOAP supports security protocols like WS-Security, which can be used to
sign and encrypt SOAP messages, ensuring confidentiality and integrity.
4. Extensibility:
○ SOAP is highly extensible, allowing developers to add features like security,
transaction management, and routing to the communication using SOAP
headers.
Disadvantages of SOAP Communication:

1. Complexity:
○ SOAP messages are more complex and verbose compared to simpler
alternatives like REST, due to the use of XML and additional metadata
(headers, envelopes).
2. Performance Overhead:
○ The use of XML, along with the SOAP envelope and headers, results in larger
messages and thus more bandwidth usage compared to other protocols like
REST.

Conclusion:

SOAP communication is a reliable and structured way for applications to communicate over
a network, offering features like security, extensibility, and cross-platform compatibility. It is
widely used in enterprise environments where reliability, security, and well-defined service
contracts are crucial. While it may be more complex and heavy compared to alternatives like
REST, it is ideal for applications that require formal communication with built-in standards
for handling security, transactions, and message reliability.

SOAP Processing Model (10 Marks)

The SOAP (Simple Object Access Protocol) Processing Model defines how messages are
processed as they travel between the originator, intermediaries, and final recipient. This
protocol is widely used for exchanging structured information in web services.

Key Components of SOAP Processing

1. SOAP Nodes:
○ Originator: The node that sends the SOAP message.
○ Intermediary: Any node that processes the message and forwards it to the
next node.
○ Recipient: The final destination that processes the message body.
2. Message Flow: SOAP messages consist of a Header and a Body. Headers contain
metadata, while the body holds the message payload (data). The message flows
through several nodes, each having specific roles based on the header entries.
3. SOAP Headers and Actor Attribute:
○ Headers: SOAP headers can be used by nodes to process specific instructions.
Headers are used to pass additional information and control how the message
is processed.

Actor Attribute: Each header can include an actor attribute that specifies which node is
responsible for processing it. For example:

<env:Header>

<x:action soap:actor="http://example.com/intermediary"/>

</env:Header>

○ This means that the node at http://example.com/intermediary must handle this


part of the message.
4. Processing Steps: Each SOAP node processes a message in the following order:
○ Message Verification: Ensures that the message is well-formed (i.e.,
conforms to the SOAP structure).
○ Header Processing: The node checks if any headers are targeted at it (via the
actor attribute) and processes them accordingly. If a header has the
mustUnderstand attribute, it means the node must process it; otherwise, an
error will be generated.
○ Intermediary Handling: If the node is an intermediary, it processes the
headers and forwards the message to the next node.
○ Final Recipient: When the message reaches the final recipient, it processes
the body of the SOAP message.
5. MustUnderstand Attribute:

This attribute is critical for ensuring that mandatory headers are processed. If a node
encounters a mustUnderstand attribute on a header that it cannot process, it must reject the
message and generate a fault.

For example:
<x:SomeHeader soap:mustUnderstand="1"/>

○ This tells the node it must process this header or report an error.
6. Routing and Intermediary Role: SOAP allows messages to be routed through
multiple intermediaries. Each intermediary can process parts of the message (usually
headers) and then forward the message. This hop-by-hop processing makes SOAP
highly flexible and allows for distributed systems where different nodes perform
specialized tasks.
7. Caching: SOAP intermediaries can enhance message processing by caching
responses to frequent requests. This feature reduces redundant processing and
improves performance. For instance, if a special cache server is set as an actor in the
message header, it can cache the response for future requests.
Example of SOAP Message Flow

Here’s a typical flow of a SOAP message through different nodes:

[Originator] ---> [Intermediary Node 1] ---> [Intermediary Node 2] ---> [Final Recipient]

Each intermediary node processes the headers meant for it, adds new headers if needed, and
forwards the message. The final recipient processes the body of the message.

Importance of the SOAP Processing Model

The SOAP processing model enables:

● Scalability: By distributing processing tasks across multiple nodes.


● Flexibility: As each intermediary can add or modify headers, allowing for dynamic
routing.
● Reliability: Ensures that mandatory parts of the message (those with
mustUnderstand) are always processed, improving fault tolerance.

In web services, bindings define how operations of a web service are transmitted between the
client and the service. They specify the protocol used and the format of the data. Here’s a
breakdown of the types of bindings you've mentioned:

1. SOAP Bindings

● SOAP (Simple Object Access Protocol) is a protocol for exchanging structured


information in the implementation of web services.
● SOAP bindings specify how the SOAP messages are transmitted over different
transport protocols (like HTTP, SMTP, etc.).
● A SOAP binding is defined in the WSDL (Web Services Description Language)
document under the <binding> element. The binding includes:
○ Transport Protocol: The protocol over which the SOAP message is
transmitted, typically HTTP or HTTPS.
○ Message Format: SOAP messages are usually formatted in XML.

Example in WSDL:

<binding name="MySOAPBinding" type="tns:MyService">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="MyOperation">
<soap:operation soapAction="urn:MyAction"/>

<input>

<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:MyService" use="encoded"/>

</input>

</operation>

</binding>

2. HTTP Bindings

● HTTP bindings specify that the web service messages are transmitted using the
HTTP protocol.
● The HTTP binding is simpler than the SOAP binding because it uses HTTP's standard
methods like GET and POST to transmit data, often in XML format.
● HTTP bindings are commonly used for lightweight web services where the overhead
of SOAP is not needed.

Example in WSDL:

<binding name="MyHTTPBinding" type="tns:MyService">

<http:binding verb="POST"/>

<operation name="MyOperation">

<http:operation location="/MyOperation"/>

<input>

<http:body use="literal"/>

</input>

</operation>

</binding>

3. SMTP-POP Bindings

● SMTP (Simple Mail Transfer Protocol) and POP (Post Office Protocol) are
protocols typically used for sending and receiving email.
● While these are not typical web service bindings in the same sense as SOAP or HTTP,
they can be used in specific applications, such as email-based web services or systems
that interact with mail servers.
● SMTP is used to send messages, and POP is used to retrieve them.

For example, a binding might define how to send or retrieve email messages through these
protocols.

● SMTP is often used for sending email (e.g., through a service like Gmail or Outlook).
● POP is used for retrieving email from a server to a local client.

These protocols can be specified in a web service context where the service sends email
notifications or retrieves data from email messages.

Example (using SMTP in a web service context):

<binding name="SMTPBinding" type="tns:EmailService">

<smtp:binding host="smtp.example.com" port="25"/>

<operation name="SendEmail">

<smtp:operation action="send"/>

<input>

<smtp:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

</input>

</operation>

</binding>

Each of these bindings provides different methods of transporting data between a web service
and its clients, depending on the needs of the application. SOAP bindings offer a more robust
and standardized message format, while HTTP bindings are lightweight and commonly used
for RESTful services, and SMTP/POP bindings are more relevant to email-based services.

SOAP security in the context of XML and web services is a crucial concern, as SOAP
messages are often exchanged over the internet and can carry sensitive information. Ensuring
the confidentiality, integrity, and authenticity of SOAP messages is essential. Below is an
overview of various SOAP security mechanisms and standards:

1. XML Security Standards

SOAP relies heavily on XML for message format, so XML security mechanisms are often
employed to secure SOAP messages:

a. XML Encryption

● XML Encryption ensures that parts of the SOAP message are encrypted to maintain
confidentiality. It allows selective encryption of elements within the XML document,
which can protect sensitive data (e.g., credit card details, passwords).
● Encrypted data is wrapped in <EncryptedData> tags.

Example:

<soap:Envelope>

<soap:Header>...</soap:Header>

<soap:Body>

<EncryptedData>

<!-- Encrypted content -->

</EncryptedData>

</soap:Body>

</soap:Envelope>

b. XML Signature

● XML Signature ensures the integrity and authenticity of the SOAP message. It allows
you to digitally sign the entire message or specific parts, preventing tampering during
transmission.
● A signature is wrapped in a <Signature> element, and typically, a public key is used
for verification.

Example:

xml
Copy code

<soap:Envelope>

<soap:Header>...</soap:Header>

<soap:Body>

<Signature>

<!-- Signature value -->

</Signature>

<SignedInfo>

<!-- Signed elements and references -->

</SignedInfo>

</soap:Body>

</soap:Envelope>

c. XML Key Management Specification (XKMS)

● XKMS simplifies the integration of public key infrastructure (PKI) into XML-based
applications. It allows SOAP-based web services to handle public keys and encryption
without dealing with complex certificate management.

2. WS-Security (Web Services Security)

WS-Security is a standard that enhances SOAP messaging with security features. It defines
how to secure SOAP messages through various mechanisms such as authentication,
encryption, and digital signatures.

Key features of WS-Security:

● Message Integrity: By using digital signatures, WS-Security ensures that SOAP


messages are not tampered with during transmission.
● Message Confidentiality: By using XML Encryption, WS-Security can encrypt
certain parts of the SOAP message, ensuring that only authorized parties can read
them.
● Authentication: WS-Security supports multiple authentication mechanisms,
including username/password tokens, X.509 certificates, and Kerberos tickets.
a. Security Tokens

● WS-Security uses tokens to authenticate and authorize SOAP messages. Common


token types include:
○ UsernameToken: Basic authentication using a username and password.
○ BinarySecurityToken: Used to pass binary tokens such as X.509 certificates
or Kerberos tickets.
○ SAML (Security Assertion Markup Language): Tokens for exchanging
authentication and authorization data.

Example with UsernameToken:

<soap:Envelope>

<soap:Header>

<wsse:Security>

<wsse:UsernameToken>

<wsse:Username>user123</wsse:Username>

<wsse:Password>password</wsse:Password>

</wsse:UsernameToken>

</wsse:Security>

</soap:Header>

<soap:Body>

<!-- SOAP body content -->

</soap:Body>

</soap:Envelope>

b. Timestamp

● WS-Security can also use a timestamp to ensure that the message is processed within
a specific time window. This prevents replay attacks (where a malicious party resends
an old message to impersonate a valid request).

Example:

<wsu:Timestamp>
<wsu:Created>2024-11-08T12:34:56Z</wsu:Created>

<wsu:Expires>2024-11-08T12:44:56Z</wsu:Expires>

</wsu:Timestamp>

3. Transport-Level Security

Transport-level security protects the entire SOAP message during transmission over the
network. The most common method is HTTPS, which is HTTP over SSL/TLS (Secure
Sockets Layer / Transport Layer Security). This method provides:

● Confidentiality: Encryption of the entire transmission.


● Integrity: The message cannot be modified during transit.
● Authentication: The server can be authenticated using an SSL certificate, and
client-side authentication can also be configured.

While transport-level security secures the communication channel, it does not provide
end-to-end security (i.e., the message is only secure between the client and the service, not
across intermediaries). That’s why message-level security (such as WS-Security) is often
used to secure SOAP messages beyond a single hop.

4. Security Policies (WS-SecurityPolicy)

WS-SecurityPolicy is an extension of WS-Security that allows web services to define


security requirements using policies. These policies are part of the WSDL and describe what
security measures must be applied to SOAP messages (e.g., signatures, encryption, tokens).

Example:

<wsp:Policy>

<sp:SignedSupportingTokens>

<wsp:Policy>

<sp:UsernameToken/>

</wsp:Policy>

</sp:SignedSupportingTokens>

<sp:TransportBinding>

<wsp:Policy>
<sp:TransportToken>

<wsp:Policy>

<sp:HttpsToken/>

</wsp:Policy>

</sp:TransportToken>

<sp:AlgorithmSuite>

<wsp:Policy>

<sp:Basic256/>

</wsp:Policy>

</sp:AlgorithmSuite>

</wsp:Policy>

</sp:TransportBinding>

</wsp:Policy>

5. SAML (Security Assertion Markup Language)

SAML is commonly used for single sign-on (SSO) in SOAP-based services. It allows secure,
token-based authentication across different domains. A SAML assertion can be used within a
SOAP message to provide authentication and authorization information.

Summary

SOAP security is achieved through a combination of message-level security (WS-Security,


XML Encryption, XML Signature) and transport-level security (HTTPS). WS-Security is
the most common standard for securing SOAP-based web services, enabling encryption,
signatures, and tokens to protect SOAP messages. It allows the protection of messages
across intermediaries and provides flexibility for various authentication and encryption
mechanisms.

WSDL

● WSDL stands for Web Services Description Language


● WSDL is used to describe web services
● WSDL is written in XML
● WSDL is a W3C recommendation from 26. June 2007

WSDL Documents
An WSDL document describes a web service. It specifies the location of the service, and the
methods of the service, using these major elements:

Element Description

<types> Defines the (XML Schema) data types used by the web service

<message> Defines the data elements for each operation

<portType> Describes the operations that can be performed and the messages
involved.

<binding> Defines the protocol and data format for each port type

The main structure of a WSDL document looks like this:

<definitions>

<types>

data type definitions........

</types>
<message>

definition of the data being communicated....

</message>

<portType>

set of operations......

</portType>

<binding>

protocol and data format specification....

</binding>

</definitions>

WSDL Example
This is a simplified fraction of a WSDL document:

<message name="getTermRequest">
<part name="term" type="xs:string"/>

</message>

<message name="getTermResponse">

<part name="value" type="xs:string"/>

</message>

<portType name="glossaryTerms">

<operation name="getTerm">

<input message="getTermRequest"/>

<output message="getTermResponse"/>

</operation>

</portType>

In this example the <portType> element defines "glossaryTerms" as the name of a port, and
"getTerm" as the name of an operation.

The "getTerm" operation has an input message called "getTermRequest" and an output message
called "getTermResponse".

The <message> elements define the parts of each message and the associated data types.
The <portType> Element
The <portType> element defines a web service, the operations that can be performed, and the
messages that are involved.

The request-response type is the most common operation type, but WSDL defines four types:

Type Definition

One-way The operation can receive a message but will not return a
response

Request-response The operation can receive a request and will return a response

Solicit-response The operation can send a request and will wait for a response

Notification The operation can send a message but will not wait for a
response

WSDL One-Way Operation


A one-way operation example:

<message name="newTermValues">

<part name="term" type="xs:string"/>


<part name="value" type="xs:string"/>

</message>

<portType name="glossaryTerms">

<operation name="setTerm">

<input name="newTerm" message="newTermValues"/>

</operation>

</portType >

In the example above, the portType "glossaryTerms" defines a one-way operation called
"setTerm".

The "setTerm" operation allows input of new glossary terms messages using a "newTermValues"
message with the input parameters "term" and "value". However, no output is defined for the
operation.

WSDL Request-Response Operation


A request-response operation example:

<message name="getTermRequest">

<part name="term" type="xs:string"/>

</message>

<message name="getTermResponse">
<part name="value" type="xs:string"/>

</message>

<portType name="glossaryTerms">

<operation name="getTerm">

<input message="getTermRequest"/>

<output message="getTermResponse"/>

</operation>

</portType>

In the example above, the portType "glossaryTerms" defines a request-response operation called
"getTerm".

The "getTerm" operation requires an input message called "getTermRequest" with a parameter
called "term", and will return an output message called "getTermResponse" with a parameter
called "value".

WSDL Binding to SOAP


WSDL bindings defines the message format and protocol details for a web service.

A request-response operation example:

<message name="getTermRequest">

<part name="term" type="xs:string"/>


</message>

<message name="getTermResponse">

<part name="value" type="xs:string"/>

</message>

<portType name="glossaryTerms">

<operation name="getTerm">

<input message="getTermRequest"/>

<output message="getTermResponse"/>

</operation>

</portType>

<binding type="glossaryTerms" name="b1">

<soap:binding style="document"

transport="http://schemas.xmlsoap.org/soap/http" />
<operation>

<soap:operation soapAction="http://example.com/getTerm"/>

<input><soap:body use="literal"/></input>

<output><soap:body use="literal"/></output>

</operation>

</binding>

The binding element has two attributes - name and type.

The name attribute (you can use any name you want) defines the name of the binding, and the
type attribute points to the port for the binding, in this case the "glossaryTerms" port.

The soap:binding element has two attributes - style and transport.

The style attribute can be "rpc" or "document". In this case we use document. The transport
attribute defines the SOAP protocol to use. In this case we use HTTP.

The operation element defines each operation that the portType exposes.

For each operation the corresponding SOAP action has to be defined. You must also specify how
the input and output are encoded. In this case we use "literal".
This element is the root of the WSDL document. It defines the name of the service
(StockQuote) and sets the namespace (targetNamespace). It also declares XML namespaces
for WSDL (xmlns) and XML Schema (xmlns:xsd).
This defines the getQuoteRequest message, which includes one part named ticker of type
xsd:string. This message is used to request a stock quote for a particular stock ticker.
This defines the getQuoteResponse message, which includes one part named result of type
xsd:float. This message represents the response that includes the stock quote as a
floating-point number.
The portType element defines a set of operations provided by the service. Here, there's one
operation called getQuote which allows the client to request a stock quote. The
parameterOrder attribute indicates that the ticker parameter is the input for the operation. The
operation has:
•An input message, tns:getQuoteRequest, which corresponds to the request message defined
earlier.
•An output message, tns:getQuoteResponse, which corresponds to the response message
defined earlier.

You might also like