Answered by:
File Names are not coming properly while executing Receive Pipeline from Orchestration.

Question
-
Hi,
We receive zip file then we have to unzip and then process all the files in zip folder based on the file name. Here we implemented custom pipeline component to unzip and executing this custom receive pipeline from the orchestration. We are able to get the files but file names are not coming properly (File names are coming same for all unzipped files (first file name is coming for all) ). Please help if you have any idea. Thanks
Here is Unzip logic.
public void Disassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
{
string schemaNS = "https://Smc.Imaging.BizTalk.Schemas.PropertySchema1";
string fileNS = "http://schemas.microsoft.com/BizTalk/2003/file-properties";
IBaseMessage Temp = inmsg;
using (ZipFile zip = ZipFile.Read(inmsg.BodyPart.GetOriginalDataStream()))
{
//zip.SortEntriesBeforeSaving = true;
foreach (ZipEntry e in zip)
{
var ms = new MemoryStream();
IBaseMessage outMsg;
outMsg = pc.GetMessageFactory().CreateMessage();
outMsg.AddPart("Body", pc.GetMessageFactory().CreateMessagePart(), true);
outMsg.Context=inmsg.Context;
e.Extract(ms);
string XMLMessage = Encoding.UTF8.GetString(ms.ToArray());
MemoryStream mstemp = new System.IO.MemoryStream(
System.Text.Encoding.UTF8.GetBytes(XMLMessage));
outMsg.GetPart("Body").Data = mstemp;
outMsg.Context.Promote("individualFileName", schemaNS, e.FileName);
_msgs.Enqueue(outMsg);
}
}
}Sunday, October 13, 2013 5:28 PM
Answers
-
The reason for the problem is pretty simple. The .Context property is a reference to a Context instance so by doing:
outMsg.Context=inmsg.Context;
your referencing the same Context object, the one belonging to the original message, with all your new messages, that's why the result is always the first.
What you need to do is copy the values, one-by-one, to the Context instance of the new message. See here for a sample: http://www.modhul.com/2007/03/08/custom-disassembler-component-remember-the-context-properties/
- Proposed as answer by Verma.Sumit Monday, October 14, 2013 3:41 AM
- Marked as answer by Ratnak Wednesday, October 16, 2013 4:54 PM
Sunday, October 13, 2013 6:24 PMModerator
All replies
-
The reason for the problem is pretty simple. The .Context property is a reference to a Context instance so by doing:
outMsg.Context=inmsg.Context;
your referencing the same Context object, the one belonging to the original message, with all your new messages, that's why the result is always the first.
What you need to do is copy the values, one-by-one, to the Context instance of the new message. See here for a sample: http://www.modhul.com/2007/03/08/custom-disassembler-component-remember-the-context-properties/
- Proposed as answer by Verma.Sumit Monday, October 14, 2013 3:41 AM
- Marked as answer by Ratnak Wednesday, October 16, 2013 4:54 PM
Sunday, October 13, 2013 6:24 PMModerator -
Hi,
Another option is to use the CloneMessageContext method on the PipelineUtil class, provided by BizTalk.
Regards,
René
Sunday, October 13, 2013 7:17 PM -
Thanks for the reply
Can you please give example how to use CloneMessageContext method
Sunday, October 13, 2013 10:41 PM -
Hi Ratnak,
You will have to use following code :
outMsg.Context = PipelineUtil.CloneMessageContext(InMsg.Context);
You can go through following example:
Unzip Files in a pipeline component
I hope this helps!!!!!!
Maheshkumar S. Tiwari|BizTalk Developer Interview Questions and Answers
http://tech-findings.blogspot.com/
- Proposed as answer by Verma.Sumit Monday, October 14, 2013 3:41 AM
Monday, October 14, 2013 2:10 AM