I'm working on a web application that runs with ASP.Net 3.5
Somewhere in the application, I'm making calls to an external system. This call consists on downloading a string from a specific url :
string targetUrl = BuildMyUrl();
WebClient wc = new WebClient();
string data = wc.DownloadString(targetUrl);
This code works quite well with a acceptable response time (under 500ms).
However, in specific cases this response time is over 15 seconds. I can reproduce the behavior, and I can clearly see the long time is on the DownloadString
call.
I don't understand why this occurs in my scenario.
You will say : "Hey, it's the target system that is slow". But I was not able able to reproduce the behavior outside my application (I've build a small console application that isolate the faulting code. Never get any issue).
I don't know where to look now to understand the issue. What can cause a simple download data to be be lengthy ?
FYI: the target system is an authentication service. The target url is of kind :
httpS://mysystem/validate?ticket=XXXYYY
Maybe the https protocol is the issue.
Does using WebClient class under IIS can alter the behavior of the WebClient ?
[Edit] I've tried :
- To explicitly set the
Proxy
property of the WebClient object to null I've replaced the DownloadData call by this code :
var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(targetUrl)); using (var response = (HttpWebResponse)req.GetResponse()) { using (var sr = new StreamReader(response.GetResponseStream())) { data= sr.ReadToEnd(); } }
None of this test were successful.
Try to use Fiddler or some integrated network analyzer inside Chrome/FF browsers to see the HTTPS requests/responses and their headers.
The latency was due to a certificate validation timeout. One of the issuer in the chain was not correctly deployed in the client server.
来源:https://stackoverflow.com/questions/9581369/slow-webclient-downloadstring