Created
April 30, 2013 22:30
-
-
Save wizact/5492446 to your computer and use it in GitHub Desktop.
Handling incoming streams in WCF when transmode is set to streaming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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