Making the original data stream seekable in a custom BizTalk pipeline

In BizTalk

pipelineThis blog post is about creating a custom BizTalk pipeline that allows the original data stream to be seekable. If the position of this stream is not reset when it’s returned then the message will be empty as it is by default forward-only.

A seekable stream in a pipeline

I won’t go into details of how the pipeline is structured, which interfaces to implement, etc. You can find the full documentation on how to create a custom BizTalk pipeline at this MSDN article.

Let’s first have a look at the most important method of the pipeline: Execute. This is the main method of the pipeline which is called with context and the actual message being processed is passed to it as parameters.

From the code sample above we have two interesting things happening:

  • A method called CreateSeekableMessage is called which takes the type IBaseMessage as parameter
  • A method called ResetMessageStream is finally called before the message is returned

Let’s have a closer look at the CreateSeekableMessage-method and see exactly what it does.

In this method a new object of type ReadOnlySeekableStream is created from the original data stream. From here on the stream will be seekable which means we can read from it and ultimately reset the position and pass it back and into BizTalk’s message box!

So without pause let’s dive into the ResetMessageStream-method!

This method does just what it says: resets the stream of the message-object to position 0!

Final words

blackboardWhen creating pipelines try to keep the complexity to a minimum. I have seen pipelines where all logic has been stuffed into the Execute-method. While the pipeline might do its job the next developer having a look at your code is going to have a bad day.

Try to make your code as readable as possible!

Recent Posts
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt

Start typing and press Enter to search