Herong's Tutorial Notes on Web Service and SOAP
Dr. Herong Yang, Version 2.11

SOAP Encoding

Part:   1  2  

(Continued from previous part...)

Multiple References and Circular References

To help serializing multiple reference, SOAP encoding specification offers the following rule:

6. When serializing an labeled inbound edge, "enc:id" attribute can be added to provide an identification to the node. If this node has other labeled inbound edges, they can be serialized with "enc:ref" attributes to refer to the node by the identification defined in the "enc:id" attribute. Of course, the value of "enc:id" must be unique.

Example 5 - Multi references: The following graph represents two compound values sharing the same sub value.

   --- Bill -->( )--- mother --->               
                                ( )<-- Mary ---
   --- Mike -->( )--- sister --->               

Using the "enc:id" and "enc:ref" attributes, this graph can be easily serialized as:

   <Mary enc:id="101"/>
   <Bill>
    <mother enc:ref="#101"/>
   </Bill> 
   <Mike>
    <sister enc:ref="#101"/>
   </Mike> 

Example 6 - Circular References: The following graph represents two compound values has each other as their sub values.

                 <--- son ------
   --- Bill -->( )             ( )<-- Mary ---
                 --- mother --->               

Using the "enc:id" and "enc:ref" attributes, this graph can also be easily serialized as:

   <Mary enc:id="101">
    <son enc:ref="#102"/>
   </Mary> 
   <Bill enc:id="102">
    <mother enc:ref="#101"/>
   </Bill> 

Node Types

To help identifying the type of node, SOAP encoding specification also offers the following rule:

7. When serializing an labeled inbound edge, "enc:nodeType" attribute can be added to indicate what kind of a value this node represents. "enc:nodeType" may be one of the strings "simple" or "struct" or "array".

Example:

   <currentCustomer enc:nodeType="struct">
    <id enc:nodeType="simple">2321</id>
    <name enc:nodeType="simple">Herong</name>
    <isSmoking enc:nodeType="simple">false</isSmoking>
   </currentCustomer>

SOAP Encoding Attributes and Namespace

As we can see from the previous sections, SOAP encoding specification defines the following attributes in its own namespace, "http://www.w3.org/2003/05/soap-encoding".

   <... xmlns:enc="http://schemas.xmlsoap.org/soap/encoding" ...>
    <... enc:nodeType="simple" enc:id="...">
    </...>
    <... enc:nodeType="simple" enc:ref="..."/>
    <... enc:nodeType="array" enc:arraySize="..." enc:itemType="...">
     ...
    </..>
    <... enc:noteType="struct">
     ...
    </..>
   </...> 

Using SOAP Encoding in SOAP Messages

SOAP encoding can be used in SOAP header blocks and SOAP bodies by specifying the SOAP "encodingStyle" attribute as encodingStyle="http://schemas.xmlsoap.org/soap/encoding/". Here is a SOAP message example with SOAP encoding:

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
 <env:Header 
    env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
  <h:expense xmlns:h="http://www.yang.com"
     env:role="http://www.w3.org/2003/05/soap-envelope/role/next"
     env:mustUnderstand="true">
  </h:expense>
 </env:Header>

 <env:Body 
    env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
    xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
  <b:travel enc:nodeType="struct" xmlns:b="http://www.yang.com">
   <b:currency enc:id="euro">
    <b:rate>0.72</b:rate>
   </b:currency>
   <b:flight>429.00</b:flight>
  </b:travel>
  <b:shopping enc:nodeType="struct" xmlns:b="http://www.yang.com">
   <b:currency enc:ref="#euro"/>
   <b:paris enc:nodeType="array" enc:arraySize="3" enc:itemType="xsi:float">
     <b:item>29.00</b:item>
     <b:item>99.00</b:item>
     <b:item>19.00</b:item>
   </b:paris>
  </b:shopping>
 </env:Body>
</env:Envelope>

Conclusions

SOAP encoding is based on SOAP date model.

SOAP encoding basic rules are easy to remember: inbound edge makes an XML element, and outbound edges make sub elements.

Question, can a group of nodes be serialized into two different XML messages?

Part:   1  2  

Dr. Herong Yang, updated in 2006
Herong's Tutorial Notes on Web Service and SOAP - SOAP Encoding