Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Initial call in RestSharp really slow? but others after are very fast

I am making calls to a WEB API using RESTSHARP and they work fine. However, the Initial call to the API (regardless of what call it is) can sometimes take up to 10 seconds to get a response. Every other call after that is really quick. Does anyone know a way around this?

I am running a WPF 4.0 application

code:

var client = new RestClient(apiAddress);
var request = new RestRequest(Method.GET);

IRestResponse response = client.Execute(request);
like image 207
Neil Hobson Avatar asked Sep 04 '12 08:09

Neil Hobson


2 Answers

It's most likely the network settings causing this problem. I recently had the same issue and it turned out that when using HttpWebRequest or RestSharp it was trying some auto configuration to look for a proxy server.

Open the network settings in Internet Explorer and disable auto configuration for the local network. In my case this resolved the delay for the first request in RestSharp as well.

like image 194
skrause Avatar answered Sep 19 '22 17:09

skrause


I had attempted @skrause's answer, but it wasn't work for me. I spend much time, and finaly I solved it. This my sulotion.

public class SimpleWebProxy : IWebProxy
{
    public ICredentials Credentials { get; set; }

    public Uri GetProxy(Uri destination)
    {
        return destination;
    }

    public bool IsBypassed(Uri host)
    {
        // if return true, service will be very slow.
        return false;
    }

    private static SimpleWebProxy defaultProxy = new SimpleWebProxy();
    public static SimpleWebProxy Default
    {
        get
        {
            return defaultProxy;
        }
    }
}

var client = new RestClient();
client.Proxy = SimpleWebProxy.Default;
like image 23
wi11du0n Avatar answered Sep 23 '22 17:09

wi11du0n