Geeks With Blogs

Rui Machado Technologies and Information Systems


This Custom Pipeline Component for BizTalk Server 2010, receives a compressed message, unzips it and sends one message per each file that the compressed file as in it. Imagine the following scenario: you have ten files that you want to send to some destination, instead of sending ten messages (one per file) you can easily send one compressed file (with all the ten files in it), taking as only precaution  the insurance that the destination system as this component in its receive pipeline.

Building the sample

After downloading the project folder, you just need to bild it and copy the DLL generated to C:\Program Files (x86)\Microsoft BizTalk Server 2010\Pipeline Components, after that Create a new BizTalk Server Empty Project, add a new Pipeline, go to your Pipeline toolbox, right click -> Choose Item -> Pipeline Componentes -> Check the option “DisUnzip”. Now drag this component to the Dissamble fase andadd a XML Disassembler right next to DisUnzip.

Unzip Method

The main method in this project has a very simple algorythm that you can check bellow:

01 public voidDisassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc
02 , Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
03         {
04             IBaseMessage Temp = inmsg;
05             using (ZipFile zip = ZipFile.Read(inmsg.BodyPart.GetOriginalDataStream()))
06             {
07                 foreach (ZipEntry e in zip)
08                 {
09                     var ms = new MemoryStream();
10                     IBaseMessage outMsg;
11                     outMsg = pc.GetMessageFactory().CreateMessage();
12                     outMsg.AddPart("Body", pc.GetMessageFactory().CreateMessagePart(), true);
13                     outMsg.Context=inmsg.Context;
15                     e.Extract(ms);
16                     string XMLMessage = Encoding.UTF8.GetString(ms.ToArray());
18                     MemoryStream mstemp = new System.IO.MemoryStream(
19                     System.Text.Encoding.UTF8.GetBytes(XMLMessage));
21                     outMsg.GetPart("Body").Data = mstemp;
23                     _msgs.Enqueue(outMsg);
24                 }
25             }
26         }

Besides this method the dissambler component should Have the GetNext() method to enforce the pipeline to send each one of the messages that you enqueue in the Queue collection:

01 public Microsoft.BizTalk.Message.Interop.IBaseMessage
02             GetNext(Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
03         {
05             // get the next message from the Queue and return it
06             Microsoft.BizTalk.Message.Interop.IBaseMessage msg = null;
07             if ((_msgs.Count > 0))
08             {
09                 msg = ((Microsoft.BizTalk.Message.Interop.IBaseMessage)(_msgs.Dequeue()));
10             }
11             return msg;
12         }


The source code can be found and download here:
Posted on Thursday, October 4, 2012 4:46 AM | Back to top

Comments on this post: BizTalk Pipeline Custom Component Message Unzippper

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © ruimachado | Powered by: | Join free