WSDL - Literal vs Encoded SOAP Messages
In SOAP-based web services, messages exchanged between the client and the server must follow a specific format defined in the WSDL document. Two common approaches used to define how data is represented in SOAP messages are Literal and Encoded message styles. These approaches determine how the data types and structures are described and interpreted during communication.
The Literal style means that the SOAP message strictly follows the XML schema defined in the WSDL document. In this approach, the structure of the message must exactly match the XML schema definitions provided in the <types> section of the WSDL. The data is transmitted as plain XML without any additional encoding rules. This makes the message easier to validate using XML schema validation tools. Literal messages are widely used in modern web services because they provide better interoperability between different platforms and programming languages.
Literal messaging is commonly associated with two styles of web service design: document-literal and rpc-literal. In document-literal style, the SOAP body contains an XML document that represents the entire request or response message. This approach is commonly used in enterprise services because it allows flexible and structured message design. In rpc-literal style, the SOAP message represents a remote procedure call where parameters correspond directly to the operation defined in the service.
The Encoded style, also known as SOAP encoding, represents data using a set of predefined encoding rules defined by the SOAP specification. Instead of strictly following an XML schema, the data elements include additional attributes that describe how values should be interpreted. These encoding rules allow complex data structures such as arrays, objects, and references to be represented in the message. For example, encoded messages may use attributes like xsi:type or SOAP-ENC:Array to indicate data types and structures.
Although encoded messages provide flexibility in representing complex data types, they can create compatibility problems between different systems. Different platforms may interpret encoding rules differently, which can lead to interoperability issues. Because of these challenges, encoded style messaging is generally considered outdated and is rarely used in modern web services.
Today, most web service implementations prefer the document-literal approach because it ensures better standard compliance, easier validation, and greater compatibility across different technologies. Many modern frameworks and standards also recommend avoiding encoded messages in favor of literal XML-based messaging.
In summary, the difference between literal and encoded SOAP messages lies in how data is structured and interpreted within the SOAP message. Literal messages strictly follow XML schema definitions and are widely used for reliable and interoperable services. Encoded messages rely on SOAP-specific encoding rules to represent complex data structures but are less commonly used due to compatibility concerns.