biztalk - Only part of stream is being written in pipeline component -


i'm building pipeline component can convert image format format (say jpg png example):

using (system.drawing.bitmap bmpsource = (system.drawing.bitmap)system.drawing.bitmap.fromstream(msgreceived.bodypart.data)) {     virtualstream strconvertedimage = new virtualstream();      bmpsource.save(strconvertedimage, system.drawing.imaging.imageformat.png);      strconvertedimage.flush();     strconvertedimage.position = 0;      ctxpipeline.resourcetracker.addresource(strconvertedimage); }  msgreceived.bodypart.data = strconvertedimage; 

i use component in receive pipeline file adaptor, , executes fine, when subscribe passthrough send port , file adaptor, file written part of actual image.

note:

i can use same code (with exception of loading source bitmap file stream instead biztalk message stream) in windows console application , works fine, seems biztalk related.

i think has source stream.

it seems odd behavior, if inspect length , position properties of msgreceived.bodypart.data, length 904678. position 0. position stays @ 0 , never changes bitmap loaded , saved. have expected load bitmap, position changes, unless bitmap.fromstream method seeks beginning of stream once it's finished loading.

also, when save bitmap new stream png, new stream length 54789, representing first party of image. if save same bitmap object new stream again, it's size 1400868, representing entire image , msgreceived.bodypart.data.position 904678 indicating entire source stream has been read.

here's example:

using (system.drawing.bitmap bmpsource = (system.drawing.bitmap)system.drawing.bitmap.fromstream(msgreceived.bodypart.data)) {     virtualstream strconvertedimage = new virtualstream();     bmpsource.save(strconvertedimage, system.drawing.imaging.imageformat.png);     strconvertedimage.flush();     strconvertedimage.position = 0;      //msgreceived.bodypart.data.position 0     //msgreceived.bodypart.data.length 904678     //strconvertedimage.position 54789 (only part of image saved)      strconvertedimage = new virtualstream();     bmpsource.save(strconvertedimage, system.drawing.imaging.imageformat.png);      //msgreceived.bodypart.data.position 904678     //msgreceived.bodypart.data.length 904678     //strconvertedimage.position 1400868 (full image saved)      msgreceived.bodypart.data = strconvertedimage;     ctxpipeline.resourcetracker.addresource(strconvertedimage); } 

why position of msgreceived.bodypart.data advance on second save? , why first save attempt save part of converted image. i'm baffled!

i'd avoid using data property except set stream @ end; per msdn clones data stream , gives unexpected behavior (i've seen data property null in adapters though getoriginaldatastream() returned stream). use getoriginaldatastream() instead. i'd avoid using using blocks in pipeline - while can't see why example problem, gets easy mistakenly dispose of stream ends disposing of original data stream.

for example,

stream originalstream = msgreceived.bodypart.getoriginaldatastream(); originalstream.seek(0, seekorigin.begin); virtualstream vtsconvertedimage = new virtualstream() system.drawing.bitmap bmpsource = (system.drawing.bitmap)system.drawing.bitmap.fromstream(originalstream);  bmpsource.save(vtsconvertedimage, system.drawing.imaging.imageformat.png);  vtsconvertedimage.flush(); vts.convertedimage.seek(0, seekorigin.begin);  msgreceived.bodypart.data = vtsconvertedimage; ctxpipeline.resourcetracker.addresource(vtsconvertedimage); ctxpipeline.resourcetracker.addresource(bmpsource); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -