Bug in HttpWebRequest/Response Dispose() implementation?



Hello,

We have a simple piece of code that exchanges data using HTTP
request/reponse. It uses "using" statement to guarantee that the
communication channel is properly closed on completion. However, if the code
is executed multiple times, the first execution attempt works fine, but the
second attempt times out.

To verify if the channel is closed properly, we replaced that code with the
following:

HttpWebRequest request = PrepareRequest(userVerificationData,
schufaRequestType, null);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

string requestID = response.Headers["RequestID"];
try
{
// Do something
}
finally
{
request = null;
response = null;
GC.Collect();
}

Then suddently everything worked! But the difference is that now we call
expensive garbage collection which of course kills the performance.

Why using Dispose method does not do the same? Isn't it the purpose of
IDisposable interface?

Vagif Abilov
Oslo Norway


.



Relevant Pages

  • Re: WebResponse timeout?
    ... "Bob" wrote: ... I managed to cause our inhouse Webserver to not respond to a request. ... Stream streamResponse; ... HttpWebResponse response; ...
    (microsoft.public.dotnet.languages.csharp)
  • WebResponse timeout?
    ... I managed to cause our inhouse Webserver to not respond to a request. ... The requesting code just sat there waiting patiently. ... Stream streamResponse; ... HttpWebResponse response; ...
    (microsoft.public.dotnet.languages.csharp)

Loading