Microsoft KB Archive/867803

= A message that is outside a Construct Message shape may not update in BizTalk Server 2004 =

Article ID: 867803

Article Last Modified on 1/11/2005

-

APPLIES TO


 * Microsoft BizTalk Server 2004 Standard Edition

-





INTRODUCTION
In Microsoft BizTalk Server 2004, if a schedule tries to assign an XML document to a message that is outside a Construct Message shape, the XML representation will be updated. However, the underlying message object will not be updated.

For example, a schedule receives a message that is named Message_1 in a Receive shape. The message has a variable that is named xmlDoc of type XmlDocument and has the following code in an Expression shape: xmlDoc = Message_1;

// The following function that is in a referenced assembly modifies the XmlDocument. DoModifications(xmlDoc);

Message_1 = xmlDoc; Then, any subsequent reference to the XML representation of the Message_1 message returns the modified XmlDocument. However, references to the message itself will return the original data.

For example, a subsequent Expression shape contains the following code: xmlDoc = Message_1; xmlDoc.Save(@&quot;C:\Temp\message1.xml&quot;); In this example, the saved file would contain the modified document. However, if you then add a Send shape to the schedule to send the Message_1 message, the message that is sent would be the original, unmodified message.



MORE INFORMATION
Messages that are inside a BizTalk Server-based server are immutable. They cannot be modified as soon as they have been constructed. The initialization of a message and all modification to a message should occur in a Construct Message shape for the message. The XML representation for the message can still be retrieved and manipulated outside the Construct Message shape. However, the underlying message representation itself will not be updated with any changes to this XML representation.

To update a message, a schedule should retrieve the original message, modify the data, and then assign the modified data to a new message that is inside a Construct Message shape for the new message. In the following example, a schedule has messages that are named Message_1 and Message_2. The schedule also has a variable that is named xmlDoc of type XmlDocument. To update the Message_1 message, follow these steps:  Drop a Construct Message shape on the design surface that is under the shape where the Message_1 message is assigned. Set the Messages Constructed property of the Construct Message shape to Message_2. Add a Message Assignment shape inside the Construct Message shape.  Set the Expression property of the Message Assignment shape to code that is similar to the following: xmlDoc = Message_1;

// The document should be cloned so the XML document for the Message_1 message // is no longer pointed to the following: xmlDoc = (System.Xml.XmlDocument)(xmlDoc.Clone);

// In a referenced assembly, this function modifies the XmlDocument. DoModifications(xmlDoc);

// Assign the updated document to the Message_2 message. Message_2 = xmlDoc; The orchestration now contains the original message (Message_1) and an updated version of the message (Message_2). 

