3
votes

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.

2
does this happen under heavy load conditions ?Felice Pollano
@FelicePollano: no. It occurs on a specific case, I.E. after a signout, then signin again on the authentication system. But only from the consumer web app (not from the test console application).Steve B
The WebClient is really slow. I would normally go for a simple sockets approach but that would be really hard to do for https.CodingBarfield
@CodingBarfield: it works under 250ms for most of my calls which are acceptable. My problem is to understand why in a specific scenario it takes 15seconds. And I hardly see the benefits of rewriting the http protocol. I guess Microsoft's army have better skills than me (and the firepower to unit test every case)Steve B
You only need to write the part of the HTML protocol that you need. Which could be pretty small and pretty simple and pretty fast. I remember using the webbrowser control for https data and simply load the document html instead of using the webclient.CodingBarfield

2 Answers

0
votes

Try to use Fiddler or some integrated network analyzer inside Chrome/FF browsers to see the HTTPS requests/responses and their headers.

0
votes

The latency was due to a certificate validation timeout. One of the issuer in the chain was not correctly deployed in the client server.