VirtualStream and ReadOnlySeekableStream
When you write a custom pipeline component, loading entire message into memory should be avoided. If you use Memory Stream for large files, it loads entire message into memory and you may have OutOfMemory exceptions. On the other hand, VirtualStream uses Biztalk’s buffering directory after a threshold value which is specified in object initialization.
In addition to this, default message stream can be non-seekable and you may have exception when you try to change message data postion. The solution for this to use ReadOnlySeekableStream which wraps MemoryStream by default.
As a result of these, It is a good approach to use ReadOnlySeekableStream and VirtualStream classes exposed by Microsoft.Biztalk.Streaming.dll together in your custom pipeline components.
Please check below code snippet to see how to use ReadOnlySeekableStream vith VirtualStream.
int bufferSize = 0×280;
int thresholdSize = 0×100000;
if (!inmsg.BodyPart.GetOriginalDataStream().CanSeek)
{
Stream virtualStream = new VirtualStream(bufferSize, thresholdSize);
ReadOnlySeekableStream seekableStream =
new ReadOnlySeekableStream(inmsg.BodyPart.GetOriginalDataStream());
Stream seekStream =
new ReadOnlySeekableStream(inmsg.BodyPart.GetOriginalDataStream(),
virtualStream, bufferSize);
inmsg.BodyPart.Data = seekableStream;
}
inmsg.BodyPart.Data.Position = 0;
Related posts:
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
