I´m writing a function to do a query to a webservice, hosted locally on my computer. It works fine, but the GetResponse method is taking more time than what I expect. More specifically, when I do the request on my browser, it takes about 10 milliseconds and the GetResponse method is taking far from that like 300 milliseconds.
Am I doing something wrong on the code?, something I can improve?
public static string CargarListaRutas()
{
WebRequest request = HttpWebRequest.Create("http://localhost:8080/services/rest/184108301/listaRutas/");
request.Timeout = 2000;
WebResponse response;
string responseFromServer;
try
{
using (response = request.GetResponse())
{
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
}
}
catch
{
responseFromServer = String.Empty;
}
return responseFromServer;
}