public Stream ProcessRequestReturnStream(XLANGMessage message, int bufferSize, int thresholdSize)
{
...
try
{
using (VirtualStream virtualStream = new VirtualStream(bufferSize, thresholdSize))
{
using (Stream partStream = (Stream)message[0].RetrieveAs(typeof(Stream)))
//Note that when calling this code, if the XmlDocument is quite large, keeping it in a memory with a MemoryStream may have an adverse effect on performance.
//In this case, it may be worthwhile to consider an approach that uses a VirtualStream + ReadonlySeekableStream to buffer it to the file system, if its size is bigger than the thresholdSize parameter.
//Keep in mind that:
// - If the message size is smaller than the threshold size, the VirtualStream class buffers the stream to a MemoryStream.
// - If the message size is bigger than the threshold size, the VirtualStream class buffers the stream to a temporary file.
using (ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(partStream, virtualStream, bufferSize))
{
using (XmlReader reader = XmlReader.Create(readOnlySeekableStream))
{
}
}
}
}
}
catch (Exception ex)
{
}
finally
{
message.Dispose();
}
return stream;
}