BizTalk Server 2006: Archive Pipeline Component

In BizTalk Server 2002 I wrote a custom pipeline component in C# to archive inbound messages “just in case” something messed up and the interchange was lost. In BTS2004 I used Gilles Zunino’s [MSFT] excellent Archiver pipeline component.


Unfortunately, this component was causing some issues when I began using it in BizTalk Server 2006 due to breaking changes to the .NET Framework, so I needed to update the source code for .NET 2.0 and BTS2006. The new Archive custom pipeline component source code can be downloaded from here!


The “heart” of the code is shown below:



public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)


        {


            Stream originalStrm = null;


            FileStream fileArchive = null;


            BinaryWriter binWriter = null;


            const int bufferSize = 1024;


 


            try


            {


                IBaseMessagePart bodyPart = inmsg.BodyPart;


 


                if (bodyPart != null)


                {


                    string path = filePath + “.” + fileExtension;


                    path = path.Replace(“%MessageID%”, inmsg.MessageID.ToString());


 


                    originalStrm = bodyPart.GetOriginalDataStream();


 


                    fileArchive = new FileStream(path, FileMode.Create, FileAccess.Write);


                    binWriter = new BinaryWriter(fileArchive);


 


                    byte[] buffer = new byte[bufferSize];


                    int sizeRead = 0;


 


                    while ((sizeRead = originalStrm.Read(buffer, 0, bufferSize)) != 0)


                    {


                        binWriter.Write(buffer, 0, sizeRead);


                    }


                }


            }


            catch(Exception ex)


            {


                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.Message + “\n” + ex.StackTrace, EventLogEntryType.Error);


            }


            finally


            {


                if (binWriter != null)


                {


                    binWriter.Flush();


                    binWriter.Close();


                }


                originalStrm.Seek(0, SeekOrigin.Begin);


            }


            return inmsg;


        }


Now why would anyone need to archive inbound messages since BizTalk Server 2006 provides such robust tracking tools? 


Two basic reasons:



  • I’m very anal about “losing” inbound trading partner data and really hate to ask them to “resend” something, even if it didn’t parse in the first place.


  • For compliance and audit reasons many customers want to make sure we keep an “unaltered” copy of their original interchange and we almost always normalize documents using a map on the inbound port.

The Archive pipeline component is a really simple way to do satisfy both of these issues and it provides the added value of helping the developer “see” the inbound interchange as it’s received in the pipeline.


Please feel free to download and use this code as you see fit. It’s provided “as is” however and has not been tested with all the BTS2006 Adapters.


My thanks to Gilles Zunino for his original source code and to Martijn Hoogendoorn for his Pipeline Component Wizard.

This entry was posted in BizTalk Server. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

7 Responses to BizTalk Server 2006: Archive Pipeline Component

  1. Jessica says:

    claret burden �compares attitudesfirst-of-its-kind
    car insurance calculatorsof theircountry:
    *to accomplish
    [url=http://carinsuranceimported.com/auto-insurance-in-regions/56-north-carolina-auto-insurance]north carolina auto insurance[/url]Approved exercise isaccumulatemaintained at atomic

  2. Zeeshan Shah says:

    Great stuff Jeff – thats simple and easy .. Works like a charm..

  3. michael isbell says:

    the file for the archive pipeline component is corrupted and can’t be downloaded.

    misbell_contractor@ap.org

  4. SidAhmed says:

    I’m working in the enterprise Mattel in Mauritania.
    We are interested for the applications, which does the DMS(Document management System) .
    We finf the BIzTalk Server, but we don’tknow if BizTalk Server 2006 archive.

  5. Anand says:

    i’m not able to call enterprise library 2.0 exception policy inside pipeline custom component even thoug i added appdomain to configure app.config.

  6. jlynch says:

    Nick,

    This component was design for receive pipelines as a “Decoder” component only. It should work as an “Encoder” component but you’ll need to add the encoder component category attribute to the class. Also, there is a difference between using the GetOriginalDataStream() method and the BodyPart.Data property that is not well documented. The GetOriginalDataStream method returns a cloned stream which is seekable, so that’s what I use.

  7. Nick says:

    I’ve got a problem when trying to archive an outbound message.
    It works fine in pass thru scenario but if I use it after XML assembler it throws an error “ForwardOnlyEventingReadStream does not support Seek()” (when originalStrm.Seek(0, SeekOrigin.Begin) ).
    I tried to use bodyPart.Data instead of GetOriginalDataStream() and comment Seek() but then “Root element is missing” error arised.

    Have you tried to use Archiver within Send Pipelines?

    Any help is highly appreciated. Feel free to contact me on nick.2006 /* hmm */ optusnet.com.au

Leave a Reply