Tech and Media Labs
This site uses cookies to improve the user experience.




SOAP Body

Jakob Jenkov
Last update: 2014-05-23

The SOAP Body element is the element in a SOAP message that contains the main part to be processed by either client or web service. While a Header element is optional, a Body element is mandatory. You MUST have a Body element in a SOAP message.

Here is a sample SOAP Body element (Body element marked in bold):

<?xml version="1.0"?>
<env:Envelope  xmlns:env="http://www.w3.org/2001/12/soap-envelope" >

<env:Header>
</env:Header>

<env:Body>
</env:Body>

</env:Envelope>

The body of a SOAP message can consist of pretty much whatever XML you feel like putting inthere, as long as it is valid. However, you cannot put text inside the Body element. Text should be nested inside child elements of the Body element.

It is recommended that child elements of the Body element are name space qualified.

Here are two Body element examples. The first example sends 4 parameters (elements) separately inside the Body element. The second example nest these 4 parameters inside a <service> element.

<?xml version="1.0"?>
<env:Envelope  xmlns:env="http://www.w3.org/2001/12/soap-envelope" >

  <env:Body>

    <jj:operation name="setName"
        xmlns:jj="http://jenkov.com/operation" />

    <jj:param name="userId" value="123456"
        xmlns:jj="http://jenkov.com/params" />

    <jj:param name="firstName" value="Jakob"
        xmlns:jj="http://jenkov.com/params" />

    <jj:param name="lastName"  value="Jenkov"
        xmlns:jj="http://jenkov.com/params" />

  </env:Body>

</env:Envelope>
<?xml version="1.0"?>
<env:Envelope  xmlns:env="http://www.w3.org/2001/12/soap-envelope" >

    <env:Body>

      <jj:service name="userService"
          xmlns:jj="http://jenkov.com/service" >

          <jj:operation name="setName" />

          <jj:param name="userId" value="123456" />

          <jj:param name="firstName" value="Jakob" />

          <jj:param name="lastName"  value="Jenkov" />

      </jj:service name="userService"

    </env:Body>

</env:Envelope>

Jakob Jenkov




Copyright  Jenkov Aps
Close TOC