Reputation: 2683
Anyone has an idea on how I could get, thru code, the current setting for maxConcurrentSessions on a session based WCF Service?
I would like to get this value even if maxConcurrentSessions is not set in the service config file, in other words, I would like to get the default value in that case.
Basically I'm trying to prove without any doubts, what the default value is for maxConcurrentSessions in my current environment.
Thanks!
Upvotes: 4
Views: 2050
Reputation: 2683
The trick is to set SOME of the throttlingBehavior attributes in the config file but to leave the maxConcurrentSessions out:
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100"/>
then on the server:
ServiceHost host = new ServiceHost(typeof(MyService));
string msg = "Service Behaviors:" + Environment.NewLine;
foreach (IServiceBehavior behavior in host.Description.Behaviors)
{
msg += behavior.ToString() + Environment.NewLine;
if (behavior is ServiceThrottlingBehavior)
{
ServiceThrottlingBehavior serviceThrottlingBehavior = (ServiceThrottlingBehavior)behavior;
msg += " maxConcurrentSessions = " + serviceThrottlingBehavior.MaxConcurrentSessions.ToString() + Environment.NewLine;
}
}
EventLog.WriteEntry("My Log Source", msg, EventLogEntryType.Information);
this gives out 800 for me. Which supports the documentation out there that says the default is 100 * nb of processors for WCF 4.0 and up.
Upvotes: 4
Reputation: 5821
this article may be of help...at the bottom there is a section on reading throttled values.
You'll need to do it server-side (e.g. inside one of your service methods). Also, in the sample it is getting the first ChannelDispatcher....for your specific scenario you may have more than 1 (unsure) depending on what you're doing so that might be a condition you also need to account for.
HTH, Nathan
Upvotes: 1