Monday, July 2, 2007

Filename Correlation

So here we go with the First ‘real’ post. The subject at hand: BizTalk and filename correlation and context property decisions.

When a message is received by BizTalk a lot of information about the file (such as it file name and receive location) is tracked by BizTalk in the context properties. When you want to edit this information or want to correlate two messages based on a context property value, you will have either promote or distinguish a context property. To accomplish this you will have to write a custom pipeline component that creates a promoted (or distinguished) context property for you.
A good example of: ‘when do I ever need such a solution?’ is posted is this forum: http://www.eggheadcafe.com/ng/microsoft.public.biztalk.server/post21008841.asp. The solution to this question is very simple: correlate all received files using the first three characters of the filename (e.g. all AAA-files and all ABC-files). In a project I did with a customer we came across a similar example where we needed to correlate two files based on their filenames.

The first thing you need to do when writing a custom pipeline component in general is download and install Martijn Hoogendoorn’s Pipeline Component Wizard: http://www.codeplex.com/btsplcw/Release/ProjectReleases.aspx?ReleaseId=2248. This wizard will create an empty pipeline component ‘shell’ in which you can write your own code without having to worry about all the standard stuff.

When you add a new project to your Visual Studio solution you can now choose a ‘BizTalk Server Pipeline Component Project’ which will start a wizard that guides you through some of the more boring stuff involved in creating a component. The component we need to create is a receive pipeline component that works in the decode stage of the pipeline:

After completing this wizard it will create a project containing our component with all the code to safely handle our six properties and initializing it for the designer. All we need to focus on is writing the code to actually promote or distinguish a given property. And since we’re at it, why not add another two properties with which we can overwrite a specified property.

In the generated class there will be a method called ‘Execute’, this is where we will do our magic. First thing we need to do is get the properties current value:

object val = inmsg.Context.Read(this.PropertyName, this.Namespace);

We can overwrite the property when the ‘OverWrite’ flag is set:

if(this.OverWrite)
val = this.Value;

Next we need to write the property back to the message but this time we promote the property while writing it:

if(this.Promote)
inmsg.Context.Promote(this.PropertyName, this.Namespace, val);

Additionally we can distinguish the property by just writing it in the message context:

if(this.Distinguish)
inmsg.Context.Write(this.PropertyName, this.Namespace, val);

After you have build, tested and deployed the component you are ready to use it. To build a solution that correlates two files based on their filenames follow the next few steps:

  • Create your own receive pipeline and add the component you’ve just created to the decode stage.
  • Set the properties to promote the FILE .ReceivedFileName property.
  • In your orchestration build a correlation type that uses the FILE.ReceivedFileName as property to correlate to.
  • Create a correlation set based on the type you’ve just created.
  • Initialize the correlation set in a receive shape within the orchestration. Use a second receive shape that follows the correlation set.
Well that’s it… of course you will need to add some code to answer the problem as posted in the forum in mentioned, but I think you should be able to figure that one out yourself (try something with regular expressions or substrings if you like).

Thursday, June 28, 2007

Well... here it is, my very own Blog. I'm still not sure if it's going to work for me, but who knows...


So, what will you be writing?
Well uhm... work I think *grin*
All the fun stuff I do with .Net and all the goodies that leave the factories in Redmond. Yeah, I'm a Microsoft guy (no not an employee), so if you're looking for the new feature in J2E, have a question about Linux, SUN OS or MAC or something else... I'm not your man.

Want some information about SQL2000/2005/2008, Visual Studio, Team System, BizTalk 2004/2006/2006R2, .Net 1.1/2.0/3.0/3.5, ASP.Net, SilverLight, WPF, etc.... hang on, maybe I'll write about those subjects in the near future. For now, it's back to work again... can't keep the customer waiting do we?

O, one more thing... If you have any comments or suggestions about anything (maybe my bad English... sorry guys I'll probably die trying), please feel free to drop a note or send me a digital postcard.