locked
Do web tests support Transfer-Encoding : chunked RRS feed

  • Question

  • Hi,

    when I run my unit test I get an error:

    System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
       at System.Net.ConnectStream.EndRead(IAsyncResult asyncResult)
       at Microsoft.VisualStudio.TestTools.WebStress.DataCaptureStream.EndRead(IAsyncResult asyncResult)
       at Microsoft.VisualStudio.TestTools.WebStress.WebTestTransaction.ReadResponse(IAsyncResult result)

    When I open the url in the browser it shows me the correct XML.

    The respond from the server is: 
    HTTP/1.1 200 OK
    Transfer-Encoding : chunked
    Cache-Control : private
    Content-Type : text/xml; charset=utf-8
    Date : Wed, 29 Oct 2008 08:25:25 GMT
    Server : Microsoft-IIS/6.0
    X-AspNet-Version : 2.0.50727

    I think it has to do with the fact that the Transfer-Encoding is chunked.

    Do web tests support this?

    Thanks,
    René
    rt
    • Moved by Chris Schmich Wednesday, October 29, 2008 6:14 PM This is a web/load test question. (Moved from Visual Studio Performance Tools (Profiler) to Visual Studio Team System - Web and Load Testing)
    Wednesday, October 29, 2008 12:28 PM

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
    • Marked as answer by Bill.Wang Monday, November 17, 2008 7:16 AM
    Tuesday, November 4, 2008 2:03 PM