locked
System.IO.IOException: Unable to read data from the transport connection: The connection was closed.

    Question

  • Hi,

    I get the following error:
    System.IO.IOException: Unable to read data from the transport connection: The connection was closed.

    When I open the URL in the browser I see the expected xml.

    I think it has to do something with then response:
    HTTP/1.1 200 OK
    Transfer-Encoding : chunked
    Cache-Control : private
    Content-Type : text/xml; charset=utf-8
    Date : Tue, 04 Nov 2008 08:59:45 GMT
    Server : Microsoft-IIS/6.0
    X-AspNet-Version : 2.0.50727

    It looks like web tests can't handle Transfer-Encoding : chunked in combination with xml.

    Other chunked responses do work:
    HTTP/1.1 200 OK
    Content-disposition : inline; filename=5-28375_master.swf
    Transfer-Encoding : chunked
    Cache-Control : private
    Content-Type : application/x-shockwave-flash
    Date : Tue, 04 Nov 2008 08:59:45 GMT
    Server : Microsoft-IIS/6.0
    X-AspNet-Version : 2.0.50727

    But this one also includes Content-disposition and content type = application/flash.

    Any ideas?

    René
     
    rt
    Tuesday, November 4, 2008 10:01 AM

Answers

  • I found the reason why.

    When I try to request the page using .Net (HttpWebRequest) I got the same error. So it's .Net framework specific.

    The exception is thrown when I call ReadToEnd on the response stream. I think .Net can't determine when the file is finished.

    When i read the file in chuncks I can read the file:

    HttpWebRequest c = WebRequest.Create(url) as HttpWebRequest;
    c.Method =
    "Get";
    c.ProtocolVersion =
    new Version(1, 1);
    c.UserAgent =
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)";
    c.Accept =
    "*/*";
    string ret = "";
    HttpWebResponse response = (HttpWebResponse)c.GetResponse();
    StreamReader sr = new StreamReader(response.GetResponseStream());
    char[] buffer;
    while (sr.Peek() >= 0)
    {
        buffer =
    new char[4096/2];
        sr.Read(buffer, 0, buffer.Length);
        ret +=
    new string(buffer);
    }
    response.Close();

    Web Test is probably using ReadToEnd instead of Read. I don't know if this behavior can be overriden.

    To fix the problem I have to use a work around.

    Instead of HTTP 1.1 I will use HTTP 1.0. When a request tells the server it uses 1.0, the server won't respond with chunked data but will send the response all at once. Of course this isn't what really happens in production but I think the difference in performance will be very small.

    René

    rt
    Tuesday, November 4, 2008 2:02 PM