Introduction
This article is the next part of the BizTalk Integration pattern series. This article discusses message oriented systems pattern known as Claim Check Pattern.
Setting the Context
In message oriented systems, during the processing of large messages we would want to remove uninteresting fields, but only temporarily and then later, when the processing is complete, we would like to add back the removed part of the message. In other words, a message may contain a set of data items that may be needed later in the message flow, but that are not necessarily required, for all intermediate processing steps. So we don't want to carry such huge amount of data in the intermediate steps, which can make debugging difficult or can cause performance degradation.
Scenario - A Store Info Processing Message
Consider a scenario where a StoreInfo
processing message needs to be processed. The elements MsgID
and MsgContent
are the only fields required for processing the message.
The Claim Check Pattern Implemented as an Orchestration
Quick Explanation...
- A Store message is received by the activatable "Receive Shape", which activates this orchestration.
- The
MsgID
is extracted from the message and assigned to messageId
variable.
messageId = StoreInMsg.Message.MsgID;
- A WebService Request message is formed.
NOTE: The variable declared in the Web Service is of type XmlDocument
and hence it can accept any schema.
WSRequest.messageId = messageId;
WSRequest.xDoc = StoreInMsg;
System.Diagnostics.EventLog.WriteEntry
("Claim Check Orchestration", "Message ID: " +
System.Convert.ToString(messageId));
- The Web request is sent to the web service and the message is persisted.
- The "Decide" shape is used to classify the message as "safe" and "unsafe". This is just an example of some processing logic.
- Once the processing is complete, again another Web Request is issued to get back the persisted message.
WSRequest2.messageId = messageId;
- The Web response is now integrated with the processing results and sent to Output Port.
StoreOutMsg = WSResponse2.RetrieveMessageResult;
StoreOutMsg.Message.MsgContent = messageContent;
System.Diagnostics.EventLog.WriteEntry
("Claim Check Orchestration", "Message Content: "+ messageContent);
The Web Service Code...
The message is stored in the Cache
object, using the messageID
as the key.
[WebMethod]
public bool PersistMessage(int messageId, XmlDocument xDoc)
{
try
{
this.Context.Cache.Add(messageId.ToString(),
xDoc, null, Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, CacheItemPriority.High, null);
return true;
}
catch
{
return false;
}
}
The message is retrieved from the Cache
object, using the messageID
as the key.
[WebMethod]
public XmlDocument RetrieveMessage(int messageId)
{
try
{
XmlDocument xDoc = (XmlDocument)
this.Context.Cache[messageId.ToString()];
this.Context.Cache.Remove(messageId.ToString());
return xDoc;
}
catch
{
return new XmlDocument();
}
}
Executing the DEMO
Input File
The InputXML file would have a blank MsgContent
element.
Event Viewer
Observe the event viewer for the messages.
Output File
The OutputXML file would have a populated MsgContent
element.
About the Downloadable Code
- Unzip the Web Service with the folder names into the C:\inetput\wwwroot directory and setup the web service.
- Unzip the BizTalk project zip file with the folder names in the C:\ drive.
- The folder KeyAndBindings contains the Bindings.xml file, which can be imported after the solution is built and deployed.
- Place the "StoreInfo_1.xml" in the In folder and check the Out folder for the response.
Some Takeaways
- Always select the "
WebPortType
" created when the "Web Reference" is added to the project, while creating "Web Ports" in the Orchestration.
Additional References
- The Architecture Journal - Messaging Patterns in Service Oriented Architecture, Part 2
- Enterprise Integration Patterns - Claim Check Pattern
Naveen has done his Masters (M.S.) in Computer science, has started his career programming the mainframes and now has more than a decade of programming, development and design experience. Naveen has a sharp eye and keen observation skills. Naveen has worked for several companies and strived hard to build large scale business applications and bringing better solutions to the table.
Quite recently Naveen has built a fairly complex integration platform for a large bank. His hobbies include training, mentoring and research. Naveen spends his free time visiting National Parks nationwide.
Naveen has developed the BizTalk Control Center (BCC)
http://biztalkcontrolcenter.codeplex.com