Ciarán Bruen
Ciarán Bruen

Reputation: 5341

WCF error - The system hit the limit set for throttle 'MaxConcurrentSessions'

I have an asp.net app that calls a WCF service. I've been having intermittent timeouts for a while so I decided to create a trace log. After getting a timeout I found the message below in the log file:

The system hit the limit set for throttle 'MaxConcurrentSessions'. Limit for this throttle was set to 10. Throttle value can be changed by modifying attribute 'maxConcurrentSessions' in serviceThrottle element or by modifying 'MaxConcurrentSessions' property on behavior ServiceThrottlingBehavior.

The thing is though I'm closing the client connection each time so I don't understand why the concurrent sessions are adding up. Below is a typical call that I make:

    try
    {
        //create proxy
        client = new CAEServiceContractClient();

        response = client.GetSecurityRecords(item); 
        totalRecords = response.TotalRecords;

        securityListView.DataSource = response.SecurityItemColl; 
        securityListView.DataBind();

        // Always close the client.
        client.Close();
        success = true;
    }
    finally
    {
        if (!success)
        {
            client.Abort();
        }
    }

So my question is, why isn't the session being destroyed once I execute client.Close()?

TIA.

Upvotes: 2

Views: 2208

Answers (1)

Allon Guralnek
Allon Guralnek

Reputation: 16131

I don't see success declared in the above code as a local variable, nor do I see you setting it to false. Could it be a class member that is being set to true on the first successful call and then staying that way?

In any case, that whole code block can be rewritten to be simpler to understand (and less bug-prone) like this:

using (var client = new CAEServiceContractClient())
{
    response = client.GetSecurityRecords(item); 
    totalRecords = response.TotalRecords;

    securityListView.DataSource = response.SecurityItemColl; 
    securityListView.DataBind();
}

The using statement ensures that when the using block has completed (normally or abnormally by an exception), the client variable will be disposed (.Dispose() will be called), thus closing the connection.

EDIT: As Ladislav Mrnka pointed out, the .Dispose() method of ClientBase has a bad habit of throwing an exception in some cases. Make sure to implement the .Dispose() method in your partial CAEServiceContractClient class as described here.

Upvotes: 1

Related Questions