Skip to content

SOAP Body — The Payload Element for Service Operations

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about SOAP Body. We cover key concepts, practical examples, and best practices to help you master this topic.

The SOAP Body is a mandatory child element of the Envelope that contains the actual payload of the message — the specific request data or response data for the invoked operation.

What You'll Learn

  • The structure and requirements of the SOAP Body
  • How request and response messages are structured
  • Error handling with SOAP Fault in the Body

Why It Matters

The Body contains the actual business data. Understanding Body structure is essential for building correct SOAP request and response messages.

Body Structure

  • Request Body — Contains the operation name as the first child element with input parameters
  • Response Body — Contains the response wrapper element with output data
  • Fault Body — Contains a single Fault element for error reporting

Code Examples

<!-- SOAP Request Body -->
<soap:Body>
  <p:PlaceOrder xmlns:p="http://example.com/orders">
    <p:CustomerID>12345</p:CustomerID>
    <p:Items>
      <p:Item>
        <p:ProductID>ABC-789</p:ProductID>
        <p:Quantity>2</p:Quantity>
      </p:Item>
    </p:Items>
    <p:ShippingAddress>
      <p:Street>123 Main St</p:Street>
      <p:City>New York</p:City>
      <p:ZIP>10001</p:ZIP>
    </p:ShippingAddress>
  </p:PlaceOrder>
</soap:Body>

<!-- SOAP Response Body -->
<soap:Body>
  <p:PlaceOrderResponse xmlns:p="http://example.com/orders">
    <p:OrderID>ORD-2024-7890</p:OrderID>
    <p:Status>Confirmed</p:Status>
    <p:EstimatedDelivery>2024-01-20</p:EstimatedDelivery>
  </p:PlaceOrderResponse>
</soap:Body>
# Extracting data from SOAP Body
root = ET.fromstring(soap_response)
ns = {'soap': 'http://schemas.xmlsoap.org/soap/envelope/',
      'p': 'http://example.com/orders'}

body = root.find('soap:Body', ns)
response = body.find('p:PlaceOrderResponse', ns)
order_id = response.find('p:OrderID', ns).text
status = response.find('p:Status', ns).text
print(f"Order {order_id}: {status}")

Common Mistakes

1. Including Multiple Body Elements

The Body can only contain one child element (the operation payload) plus an optional Fault.

2. Forgetting the Operation Wrapper Element

Parameters must be wrapped inside the operation element.

3. Missing Required Parameters

If the WSDL defines required parameters, omitting them causes a validation fault.

4. Incorrect Data Types

The Body must use data types matching the XSD schema defined in the WSDL.

5. Mixing Request and Response Structures

Request and response use different element names (e.g., PlaceOrder vs PlaceOrderResponse).

Practice Questions

  1. How many child elements can the SOAP Body contain?
  2. What is the naming convention for response elements?
  3. How does the SOAP Fault relate to the Body?
  4. What happens if the Body contains an unknown operation?
  5. Can the Body contain binary data?

Answers:

  1. One operation element plus an optional Fault element.
  2. Usually the request name with "Response" appended (e.g., PlaceOrderResponse).
  3. The Fault is placed inside the Body element for error conditions.
  4. The server returns a SOAP Fault with Client code.
  5. Yes, using base64 encoding within XML elements.

Challenge: Design the SOAP request and response Body for a shipping rate calculator. Include origin, destination, weight, and package dimensions in the request.

FAQ

Can the SOAP Body use JSON instead of XML?

: No. The SOAP spec requires XML content in the Body.

Is the Body encrypted separately from the Header?

: Yes. WS-Security supports selective encryption of Body and/or Header blocks.

What is the size limit for a SOAP Body?

: No spec limit, but practical limits are set by the server (typically 1-10 MB).

What's Next

Learn about SOAP Fault handling for error responses, then explore WS-Addressing and WS-Security.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro