I can't receive a file which is over 268435456 bytes from HttpWebResponse Stream

1

In my project, a silverlight client send a "POST" request to a http handler using HttpWebRequest and get the response, which is a zip file, from the http handler using HttpWebResponse stream. The zip file is dynamically being created during response so that the http handler can't know the file size. If the zip file size is under 268435456 bytes, the http handler complete the response without any problem. But otherwise, HttpWebResponse stream only get 268435456 bytes and Stream.Read() returns zero. After some steps, the stream is closed and a HttpException("The remote host closed the connection. The error code is 0x800704CD.") is thrown in the http handler.

client side's code snippet is here.

request.BeginGetResponse(new AsyncCallback(result =>
{
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
    using (var responseStream = response.GetResponseStream())
    {
        int read = 0;
        byte[] buffer = new byte[2048];
        while ((read = responseStream.Read(buffer, 0, buffer.Length)) > 0)
        {
            downloadStream.Write(buffer, 0, read);
        }
        ...
    }
}

If the size is over 268435456 bytes responseStream.Read(buffer, 0, buffer.Length)) returns zero. First, I think this is related with configuration in web.config or IIS. But when I sent a request to the http handler on browser by using html form I could get the entire zip file regardless of the file size. So now I think that this might be a problem of HttpWebResponse class. If you have any idea about this problem or other approach, please let me know that.

edited. I tried changing maxRequestLength in web.config, that was useless for this problem.

c#
asp.net
silverlight
asked on Stack Overflow Feb 7, 2014 by jyshin • edited Feb 12, 2014 by jyshin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0