currently in one of our apps I see big lags when executing the first HTTP Webrequest. According to our logs there is a lag of 30 - 60 seconds. It blocks at HttpWebRequest.BeginGetResponse
Here is a quote from the MSDN:
The BeginGetRequestStream method requires some synchronous setup tasks to complete (DNS resolution, proxy detection, and TCP socket connection, for example) before this method becomes asynchronous. As a result, this method should never be called on a user interface (UI) thread because it might take some time, typically several seconds. In some environments where the webproxy scripts are not configured properly, this can take 60 seconds or more. The default value for the downloadTime attribute on the config file element is one minute which accounts for most of the potential time delay.
I understand that there is DNS resolution, proxy detection and other stuff required. But 30-60 seconds is way too long. When I enter the same URL in any browser I get the page immediately. When I resolve DNS manual there is also no delay. All concurrent requests to the same URI don't block. When I restart the application the first request blocks again for min. 30 seconds.
Is this a known problem? Is there a bug? We see this on different machines, So I don't think my developer machine is the problem.
Here is some example code:
private void TestWebRequest()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://matrix.ag-software.de/http-bind");
request.ContentType = "text/xml; charset=utf-8";
request.Method = "POST";
request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
}
private void GetRequestStreamCallback(IAsyncResult result)
{
//
}
update: This must be a problem with my Windows 7 Installation. I have tested 2 other machines and can't cause the same problem there. I have seen logfiles from customers with exactly the same problems. This seems to happen under some conditions on some machines.
I have just happened through the same.
I found out that the Microsoft Client Firewall was generating it. I was using it to avoid navigate through my company's proxy. My first workaround was to set the request.Proxy hard-coded. To avoid that ugly line of code I end up disabling the Microsoft Client Firewall and setting the proxy on Internet Options.
Hope this helps.
As @EricLaw said, System.Net logging may help. Here is a link to MSDN to Enable System.Net logging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With