WCF throttling provides some properties that you
can use to limit how many instances or sessions are created at the application
level. Performance of the WCF service can be improved by creating proper
instance.
Attribute
|
Description
|
maxConcurrentCalls
|
Limits the total number of calls that can
currently be in progress across all service instances. The default is 16.
|
maxConcurrentInstances
|
The number of InstanceContext objects that
execute at one time across a ServiceHost. The default is Int32.Max Value.
|
maxConcurrentSessions
|
A positive integer that limits the number of
sessions a ServiceHost object can accept. The default is 10.
|
Administrative
(configuration file)
Using <service Throttling> tag of the Service
Behavior, you can configure the maxConcurrentCalls, maxConcurrentInstances,
maxConcurrentSessions property as shown below.
<system.serviceModel>
<services >
<service
behaviorConfiguration="ServiceBehavior" name="MyService">
<endpoint address=""
binding="wsHttpBinding" contract="IMyService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<service Behaviors>
<behavior
name="ServiceBehavior">
<service Metadata
httpGetEnabled="true"/>
<serviceDebug
includeExceptionDetailInFaults="true "/>
<service Throttling
maxConcurrentCalls="500"
maxConcurrentInstances ="100"
maxConcurrentSessions
="200"/>
</behavior>
</service Behaviors>
</behaviors>
</system.serviceModel>
Programming
Model
Use ServiceThrottlingBehavior object to set
concurrent calls, session and instance property.
Service
Host host = new Service Host (typeof (MyService));
ServiceThrottlingBehavior
throttle = host.Description.Behaviors.Find ();
If
(throttle == null)
{
Throttle
= new ServiceThrottlingBehavior ();
throttle.MaxConcurrentCalls
= 500;
throttle.MaxConcurrentSessions = 200;
throttle.MaxConcurrentInstances = 100;
host.Description.Behaviors.Add
(throttle);
}
host.Open
();
No comments:
Post a Comment