Skip to content

Instantly share code, notes, and snippets.

@wizact
Created April 30, 2013 22:30
Show Gist options
  • Save wizact/5492446 to your computer and use it in GitHub Desktop.
Save wizact/5492446 to your computer and use it in GitHub Desktop.
Handling incoming streams in WCF when transmode is set to streaming
public class StreamManager
{
private const int BufferLength = 1024;
/// <summary>
/// Receives the sourceStream from service and iterate until end of the stream
/// </summary>
/// <param name="sourceStream">Source stream</param>
/// <returns>Memory stream</returns>
public MemoryStream ReadStream(Stream sourceStream)
{
var destinationStream = new MemoryStream();
var byt = new byte[BufferLength];
int count = 0;
while ((count = sourceStream.Read(byt, 0, BufferLength)) > 0)
{
destinationStream.Write(byt, 0, count);
}
destinationStream.Position = 0;
sourceStream.Dispose();
return destinationStream;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment