none
IHttpHandler Response.Flush() does not work

    Question

  • I have folowing request handler. It's working for about 5-10 minutes.

    public class ReadStatusHandler : IHttpHandler
        {        
            public void ProcessRequest(HttpContext context)
            {
                context.Response.Clear();
                context.Response.ContentType = "application/octet-stream";
    
                context.Response.Buffer = false;
    
                using (var documentWriter = new BinaryWriter(context.Response.OutputStream))
                {
                    while (Helper.NeedNext())
                    {
                        var serializedObjectBytes 
    = System.Text.Encoding.Unicode.GetBytes(Helper.ReadMessage());
                        context.Response.Flush();
                    }
                }
    
                context.Response.End();
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }

        


    I want to get response stream in Silverlight client side. I want to read messages as they arrive:

    Uri readMessagesUri = GetReadStatusUri();
    WebRequest request = WebRequest.Create(readMessagesUri );
    
    IAsyncResult getResponseResult = request.BeginGetResponse(result =>
        {
            using (var response = request.EndGetResponse(result))
            using (var stream = response.GetResponseStream())
            using (var mesasgeEnumerator= new MesasgeEnumerator(stream))
            {
                while (statusEnumerator.MoveNext())
                {
    // writing messages to UI
                }
            }
        },
        null
    );

    But AsyncCallback is called only after context.Response.End() and I get all messages after long pause.

    Friday, March 17, 2017 4:53 AM

All replies