WCF throttling provides properties that you can use to
limit how many instances or sessions are created at the application level.
Throttling is a behavior which has three attributes:-
1.
maxConcurrentCalls :- limits total
no of calls that currently be in progress across all service instance.Default value of
maxConcurrentCalls is 16.
2.
maxConcurrentInstances :- limits the number of instanceContext objects
that execute at one time across a serviceHost. Default value is Int32.Max i.e.
2147483647.
3.
maxConcurrentSessions :- limits the
no of sessions a serviceHost Object can accept. Default value is 10.
Throttling
properties can be configured either in config file or programmatically.
Configuration File:-
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set
the value below to false and remove the metadata endpoint above before
deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for
debugging purposes, set the value below to true. Set to false before deployment to avoid
disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling
maxConcurrentCalls="10"
maxConcurrentInstances="100"
maxConcurrentSessions="10"/>
</behavior>
</serviceBehaviors>
</behaviors>
Programmatically:-
ServiceHost host = new ServiceHost(typeof(MyService));
ServiceThrottlingBehavior throttle
=
host.Description.Behaviors.Find();
if (throttle
== null)
{
throttle =
new ServiceThrottlingBehavior();
throttle.MaxConcurrentCalls = 100;
throttle.MaxConcurrentSessions
= 20;
throttle.MaxConcurrentInstances =
100;
host.Description.Behaviors.Add(throttle);
}
host.Open();
No comments:
Post a Comment
Note: only a member of this blog may post a comment.