SOAP - SOAP Encoding
1. What is SOAP Encoding?
-
SOAP encoding is a set of rules that describe how data types are represented in XML within a SOAP message.
-
Defined in the SOAP specification under the namespace:
http://schemas.xmlsoap.org/soap/encoding/
-
It tells the sender and receiver how to serialize (encode) or deserialize (decode) data like integers, strings, arrays, objects, etc., into XML format.
2. Why is SOAP Encoding Needed?
-
Different programming languages represent data types differently.
-
SOAP encoding provides a standard way to represent complex data types in XML so that:
-
A Java program can send data to a .NET program.
-
A Python client can understand a C++ server’s response.
-
3. SOAP Encoding Styles
There are two common encoding styles:
-
Literal Encoding (document/literal)
-
The XML message directly matches the schema (no extra encoding rules).
-
Most common and widely used today.
-
-
SOAP Encoding (RPC/encoded)
-
Uses the SOAP encoding rules to represent parameters in an RPC (Remote Procedure Call) style.
-
Was common in early SOAP services but now less popular.
-
4. Example: SOAP Encoding in Use
Suppose we want to send an array of integers [10, 20, 30]
.
SOAP Request with Encoding
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<ns1:getNumbers xmlns:ns1="http://example.com/">
<numbers soapenc:arrayType="xsd:int[3]"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<number>10</number>
<number>20</number>
<number>30</number>
</numbers>
</ns1:getNumbers>
</soap:Body>
</soap:Envelope>
Explanation:
-
soap:encodingStyle
→ specifies encoding rules being used. -
xsd:int
→ defines the data type (integer). -
soapenc:arrayType="xsd:int[3]"
→ tells the receiver it’s an array of 3 integers.
5. Key Points about SOAP Encoding
-
SOAP encoding defines serialization rules for data types in XML.
-
Declared using the attribute:
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
-
Handles simple types (int, string, boolean) and complex types (arrays, objects).
-
Literal encoding is more widely used today (especially with WSDL + Document/Literal style).
-
RPC/encoded style is now less common, but still important to understand for legacy systems.