Callum Metor
Callum Metor

Reputation: 77

WCF client timeout after 400 instance calls when not closing proxy

I am using the following code to investigate what happens when you fail to close the proxy:

class Program
{
    static void Main()
    {
        for (int i = 1; i < 500; i++)
        {
            MakeTheCall(i);
        }

        Console.WriteLine("DONE");
        Console.ReadKey();
    }

    private static void MakeTheCall(int i)
    {
        Console.Write("Call {0} - ", i);

        var proxy = new ServiceReference1.TestServiceClient();

        var result = proxy.LookUpCustomer("123456", new DateTime(1986, 1, 1));

        Console.WriteLine(result.Email);            

        //proxy.Close();
    }
} 

The service is using net.Tcp binding, WAS hosted, all default values.

Running it, I get a timeout when i > 400. Why 400 - is this a setting somwhere? I expected it to be much less - equal to maxConnections.

Upvotes: 2

Views: 1324

Answers (2)

MangoBrainz
MangoBrainz

Reputation: 188

By not closing the proxy, you are maintaining a session on the service. The maxConcurrentSessions throttling attribute controls how many sessions the service can accommodate. The default (in .NET 4.0) is 100 * Processor Count, so I am guessing that you have 4 processors (or cores) = 400 concurrent sessions?

Upvotes: 5

Sixto Saez
Sixto Saez

Reputation: 12680

The reason your test code is timing out is probably due to the default WCF service throttling and doesn't have anything to do with not disposing of the proxy object. To conserve client-side resource, you should always properly dispose the proxy instance.

I believe that a service host will only create up to 16 instances of a service by default which may be even less if the binding is set to use session of some sort. You're flooding it with around 400 requests within a few seconds. There are a set of WCF performance counters you can fire up and view the instancing of a WCF service. I knew all that prep for the WCF certification exam would come in really useful sometime :)

Upvotes: 0

Related Questions