Custom pipeline issue
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > BizTalk Server > BizTalk Server General > Custom pipeline issue




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Custom pipeline issue  
...


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-09-06 12:18 AM

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);
}







[ Post a follow-up to this message ]



    Re: Custom pipeline issue  
Tomas Restrepo \(MVP\)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-09-06 12:18 AM

>
> 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/







[ Post a follow-up to this message ]



    Re: Custom pipeline issue  
...


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-09-06 12:18 AM

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/
>







[ Post a follow-up to this message ]



    Re: Custom pipeline issue  
Tomas Restrepo \(MVP\)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-09-06 12:18 AM

> 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/







[ Post a follow-up to this message ]



    Re: Custom pipeline issue  
Trace Young [MSFT]


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-09-06 06: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.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:01 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register