LOW Bandwidth streaming with WCF and IIS RRS feed

  • Question

  • My service streams at a low bitrate some data via WCF 4.0 hosted on IIS 7.0 Windows 7 to clients. The question I have is about chunk size of the data delivered to the clients of my service - is there any way to control that? I need the streamed by service data to be delivered to all the clients in chunks uo to 1K in size. However, what I do see is that clients get data in 65536 byte chunks, which is not acceptable for my use case.

    My service code looks something like this:

    public Stream GetLowRealTimeStream() {

    HttpContext.Current.Response.BufferOutput = false; // this line does not make any difference

    return new MyStream(); }

    where the MyStream class looks something like this:

    public class MyStream : Stream { public override int Read(byte[] buffer, int offset, int count) { // returns not more ~100 bytes every second regardless of the count value

    } }

    When client is trying to get the response with the stream:

    var response = (HttpWebResponse) request.GetResponse();

    that call hangs until the service sends first 65536 bytes (the service stream gets first read request for 256 bytes, second for 4096 bytes, and all the subsequent requests for 65536 or 4096 depending on the maxReceivedMessageSize/maxBufferSize values). And after that clients continue getting data in chunks of 65536 bytes every N seconds via Stream.Read instead of getting ~100 bytes every second.

    I played with configuration values: maxBufferSize, maxReceivedMessageSize, maxBytesPerRead but without any success.

    Any idea on what I'm doing wrong?


    • Edited by AlexSunn Wednesday, May 1, 2013 11:45 PM
    Wednesday, May 1, 2013 11:32 PM

All replies

  • Hi,

    You may try using WCF Performance Counters to monitor the application's performance.

    Best Regards.

    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 2, 2013 10:32 AM
  • The question is not about the performance. And I do have the perf counters enabled anyway.


    Thursday, May 2, 2013 3:07 PM
  • Hi AlexSunn,

    Hope that you are doing good today.

    I had a chance to review your requirement and have been digging around to see how to help you out with the issue. I think what you need is related to chunking the channel

        public const int ChunkSize = 4 * 1024; //4KB

       internal class ChunkState
    internal ChunkState()
    this.Buffer = new byte[ChunkingUtils.ChunkSize];
    this.Count = 0;
    internal int AppendBytes(byte[] buffer, int index, int count)
    int bytesToCopy = Math.Min(count, this.Buffer.Length - this.Count);
    Array.Copy(buffer, index, this.Buffer, this.Count, bytesToCopy);
    this.Count += bytesToCopy;
    return count - bytesToCopy;
    internal byte[] Buffer;
    internal int Count;

    There is a very good blog that implements the same to process small amount of data at the client end :

    ServiceReference1.FileData fileData = new ServiceReference1.FileData();
     fileData.Filename = fileInfo.Name;
     fileData.Offset = offset;
     fileData.Buffer = 
    new byte[BUFFER_SIZE];
    FileStream fs = fileInfo.OpenRead();
     newOffset = fs.Seek(offset, 

    int read = fs.Read(fileData.Buffer, 0, BUFFER_SIZE);

    if (read != 0)
         offset += read;


    You can test with this and let me know if this works out for you or not. HTH!



    Tuesday, May 21, 2013 5:09 PM