4.1.1 Establishing Context Using SOAP 1.2

A client establishes context with a server by sending the server a Client Context Initiating Message. This message is a SOAP message [SOAP1.2-1/2007] that does not contain CONTEXT_XML as a SOAP header.

 <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http:
 //www.w3.org/2005/08/addressing">
 <s:Header>
 <a:Action s:mustUnderstand="1">http://machine1.example.org/Sample/IShoppingCart/Create</a:Action>
 <a:MessageID>urn:uuid:04133e99-4c4f-4433-b2de-4aca4132e78f</a:MessageID>
  
 <a:ReplyTo>
 <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
 </a:ReplyTo>
 <a:To s:mustUnderstand="1">http://machine2.example.org/ShoppingCart</a:To>
 </s:Header>
 <s:Body>
 <Create xmlns="http://machine1.example.org/Sample">
 <customerId>571</customerId>
 </Create>
 </s:Body>
 </s:Envelope>
  

When the server receives this message, it invokes a business logic function according to its rules for processing SOAP messages ([SOAP1.2-1/2007] section 2.6). This function creates a new shopping cart resource, associates it with a new context identifier, and creates a response message. The context identifier has a single pair (property name, property value).

 Property name

 Property value

instanceId

1a1913b1-cb24-4d94-91d2-cf414a569481

The server then transforms the response message into a Server Context Establishing Message by adding a SOAP header and sends it to the client. This header is a CONTEXT_XML element that is isomorphic to the context identifier that is associated with the shopping cart.

 <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http:
 //www.w3.org/2005/08/addressing">
 <s:Header>
 <a:Action s:mustUnderstand="1">http://machine1.example.org/Sample/IShoppingCart/CreateResponse</a:Action>
 <a:RelatesTo>urn:uuid:04133e99-4c4f-4433-b2de-4aca4132e78f</a:RelatesTo>
 <Context xmlns="http://schemas.microsoft.com/ws/2006/05/context">
 <Property name="instanceId">1a1913b1-cb24-4d94-91d2-cf414a569481</Property>
 </Context>
 </s:Header>
 <s:Body>
 <CreateResponse xmlns="http://machine1.example.org/Sample"/>
 </s:Body>
 </s:Envelope>
  

When the client receives the Server Context Establishing Message, it creates a context identifier that is isomorphic to the CONTEXT_XML element from the SOAP message and stores it.