Today was one of those days that I couldn’t resist my need to find out what happens under the BizTalk covers. I think every BizTalk developer recognizes this.
In particular I wanted to examine the context properties of message stored in the spool table. The reason I wanted to do this is a little bit irrelevant for now and might eventually come back in a future post or article.
Anyway, the spool table has a very simple structure:
CREATE TABLE [dbo].[Spool](
[uidMessageID ] [uniqueidentifier] NOT NULL,
[UserName] [sysname] NOT NULL,
[PublishingServer] [sysname] NOT NULL,
[OriginatorSID] [sysname] NOT NULL,
[OriginatorPID] [nvarchar](256) NOT NULL,
[dtTimeStamp] [datetime] NOT NULL,
[dtExpiration] [datetime] NULL,
[nvcMessageType] [nvarchar](128) NULL,
[nNumParts] [int] NOT NULL,
[uidBodyPartID] [uniqueidentifier] NULL,
[nvcBodyPartName] [nvarchar](256) NULL,
[nCounter] [int] NOT NULL,
[imgContext] [image] NULL )
The column I was interested in is called ‘imgContext’. For each message this column stores an encoded serialized value of the collection of context properties, something like this:
0xC4E0906C1849D311A24200C04F60A5330500000074000000680074007 etc, etc….
For my experiment I wanted to work in code with IBaseMessageContext interface much like the way we do when coding custom pipeline components.
So the question was how can I directly create a IBaseMessageContext instance from ‘0xC4E0906C1849D311A……’?
After clicking around for quite a while in Reflector I was able to create a very simple console application that gave me access to the context of the message. The only thing I needed to provide was the Message ID which can be fetched from the column ‘uidMessageID’ or the BizTalk Administration Console. Here is the code:
Running writes the context properties to the console:
I hope this code will help someone who, like me, also has the need to go beyond the BizTalk borders 🙂
A couple of notes:
- This code is only for ‘research’ purposes and should never be used in production environments or any other purpose.
- If you want to do this. Make sure the message stays in the spool table. If the message is processed by BizTalk and everything went fine the message will be deleted from the spool table. To prevent this you can set a breakpoint on the processing orchestration, create an error or disable the BizTalk Sql agent jobs.
- The code was developed using BizTalk 2009 but should also work in previous versions.