The structure of a SOAP message

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; see The SOAP header.
The SOAP body
<Body> is a mandatory subelement of the SOAP envelope, which contains information intended for the ultimate recipient of the message; see The SOAP body.
The SOAP fault
<Fault> is a subelement of the SOAP body, which is used for reporting errors; see The SOAP fault.

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.

The diagram shows the SOAP envelope as a container for both the SOAP header and the SOAP body.

The following code is an example of a SOAP message that contains header blocks (the <m:reservation> and <n:passenger> elements) and a body (containing the <p:itinterary> element).

<?xml version='1.0' Encoding='UTF-8' ?>
<env:Envelope xmlns:env=""> 
  <m:reservation xmlns:m="" 
  <n:passenger xmlns:n="" 
   <n:name>Fred Bloggs</n:name>
  <p:itinerary xmlns:p="">
     <p:departing>New York</p:departing>
     <p:arriving>Los Angeles</p:arriving>
     <p:departureTime>late afternoon</p:departureTime>
     <p:departing>Los Angeles</p:departing>
     <p:arriving>New York</p:arriving>