The word throttling is mainly derived from the throughput keyword. Throughput means that the work performs in a given specific time interval. The throughput of any WCF Service mainly depends on the number, for instance, the number of sessions you create. Based on the number of instance and session, you can increase and decrease the performance for WCF Service.
Controlling the number of instance and session for WCF Service, we have to use throttling. In throttling, you have to specify the number for the concurrent call and concurrent session, and the concurrent instance allows for the client to communicate with WCF Service. In throttling, you can specify it in two ways: in the app.config file of the Service or you can specify it at the hosting time programmatically.
Config File
- <behaviors>
- <serviceBehaviors>
- <behavior name="throttlingBehavior">
- <serviceThrottling
- maxConcurrentCalls="2"
- maxConcurrentInstances="2"
- maxConcurrentSessions="2"/>
- </behavior>
- </serviceBehaviors>
- </behaviors>
Programmatically
- ServiceHost host = new ServiceHost(typeof(ThrottlingInWCF.ThrottlingInWCF));
-
- ServiceThrottlingBehavior stb= new ServiceThrottlingBehavior();
- stb.MaxConcurrentCalls=2;
- stb.MaxConcurrentInstances=2;
- stb.MaxConcurrentSessions=2;
-
- host.Description.Behaviors.Add(stb);
- host.Open();
- Console.Write("Service started...");
- Console.Read();
In the commands, shown above, we specify
maxConcurrentCalls="2"
maxConcurrentInstances="2"
maxConcurrentSessions="2" - maxConcurrentCalls="2"
Here, this will show that the client can create a maximum number of 2 concurrent calls to communicate with WCF Service.
- maxConcurrentInstances="2”
Here, this will specify the client can create a maximum of 2 concurrent instances to communicate with WCF Service.
- maxConcurrentSessions="2"
Here, this will specify the client can create a maximum of 2 concurrent sessions to communicate with WCF Service.
It means the client only creates maximum number for the concurrent calls, sessions and instances as per throttling behavior. If the client crosses the limit, then the Service will not allow doing this.
As shown above, you can specify the throttling in two ways; i.e., in config file and at hosting time. Thus, we can say that using throttling in WCF, you can create hurdles for the client to communicate or access the WCF Service.