BizTalk Server General - Custom pipeline issue

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > June 2006 > Custom pipeline issue





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Custom pipeline issue
....

2006-06-08, 7:18 pm

Hi

I'm attempting to wrote a custom pipeline, in summary all I'm trying to do
is a search & replace, this is to handle creation of an XML message where
most of XML elements are within a CDATA (don't ask why - not my decision!)

Anyway, the code compiles and doesn't crash when I use with biztalk (or
pipeline.exe), it creates an empty file. The debug code at the end returns
83 which is the length of the file I expect, however the file which is
created is blank .

Any hints or better ways to do this?

Thanks


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

StreamReader ms = new StreamReader(inmsg.BodyPart.Data);
MemoryStream mms = new MemoryStream();
string content = string.Empty;

content = ms.ReadToEnd();
content = content.Replace("<cdatasection>", "<![CDATA[");
content = content.Replace("</cdatasection>", " ]]>");

byte[] imgarray = StrToByteArray(content);
mms.Write(imgarray,0,imgarray.Length);

Console.WriteLine(mms.Length);
Console.WriteLine(content);
Console.WriteLine("HELLO");
Console.WriteLine(imgarray.Length);
inmsg.BodyPart.Data = mms;
Console.WriteLine("LENGTH OF INMSG = ");
Console.WriteLine(inmsg.BodyPart.Data.Length);

return inmsg;

}
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}


Tomas Restrepo \(MVP\)

2006-06-08, 7:18 pm

>
> I'm attempting to wrote a custom pipeline, in summary all I'm trying to do
> is a search & replace, this is to handle creation of an XML message where
> most of XML elements are within a CDATA (don't ask why - not my decision!)
>
> Anyway, the code compiles and doesn't crash when I use with biztalk (or
> pipeline.exe), it creates an empty file. The debug code at the end
> returns 83 which is the length of the file I expect, however the file
> which is created is blank .
>
> Any hints or better ways to do this?
>
> Thanks
>
>
> public Microsoft.BizTalk.Message.Interop.IBaseMessage
> Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc,
> Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
> {
>
> StreamReader ms = new StreamReader(inmsg.BodyPart.Data);
> MemoryStream mms = new MemoryStream();
> string content = string.Empty;
>
> content = ms.ReadToEnd();
> content = content.Replace("<cdatasection>", "<![CDATA[");
> content = content.Replace("</cdatasection>", " ]]>");
>
> byte[] imgarray = StrToByteArray(content);
> mms.Write(imgarray,0,imgarray.Length);
>
> Console.WriteLine(mms.Length);
> Console.WriteLine(content);
> Console.WriteLine("HELLO");
> Console.WriteLine(imgarray.Length);
> inmsg.BodyPart.Data = mms;
> Console.WriteLine("LENGTH OF INMSG = ");
> Console.WriteLine(inmsg.BodyPart.Data.Length);
>
> return inmsg;
>
> }


Rewind the stream at the end just before assigning it as the body part data:

mms.Position = 0;
inmsg.BodyPart.Data = mms;


--
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/


....

2006-06-08, 7:18 pm

That worked you are my hero. Just for interest why is the rewind necessary?

Does my code look "efficient" enough? This custom pipeline is going to be
used ni a vast majority of our biztalk projects.







"Tomas Restrepo (MVP)" <tomasr@mvps.org> wrote in message
news:OivSIEziGHA.4368@TK2MSFTNGP03.phx.gbl...
>
> Rewind the stream at the end just before assigning it as the body part
> data:
>
> mms.Position = 0;
> inmsg.BodyPart.Data = mms;
>
>
> --
> Tomas Restrepo
> tomasr@mvps.org
> http://www.winterdom.com/
>



Tomas Restrepo \(MVP\)

2006-06-08, 7:18 pm

> That worked you are my hero. Just for interest why is the rewind
> necessary?


Because once you've written to the stream, the stream position is located
right at the end of it (i.e. where you finished writing). If you try to read
from it at that point, then, you're already at the end so there's nothing to
read! Hence, move back to the start of it.


> Does my code look "efficient" enough? This custom pipeline is going to be
> used ni a vast majority of our biztalk projects.


Well, it will probably work OK if your messages are not too big. Otherwise,
you'll have problems because you're buffering the entire message in memory
while doing the replacement, and that will cause you to run out of memory
with large messages (or too many concurrent messages). You can certainly
change it so that you do all replacement as the stream is read, but it
certainly takes more work.


--
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/


Trace Young [MSFT]

2006-06-09, 1:18 pm

http://support.microsoft.com/kb/905517 contains additional information.

Regards,

Trace
--------------------[vbcol=seagreen]
do[vbcol=seagreen]
where[vbcol=seagreen]
decision!)[vbcol=seagreen]
data:[vbcol=seagreen]

This posting is provided "AS IS" with no warranties, and confers no rights.
© 2006 Microsoft Corporation.
All rights reserved.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com