WCF

WCF Examples

WCF

WCF Projects

WCF Project

adplus-dvertising
Throttling
Previous Home Next

Throttling enables we to restrain client connections and the load they place on our service. Throttling enables we to ignore maxing out our service and the underlying resources it allocates and uses.

If the settings we configure are exceeded, WCF will automatically place the pending callers in a queue and serve them out of the queue in orde,When throttling is engaged. While pending in the queue,If the client's call timeout expires, the client will get a TimeoutException.

Throttling is done per service type; measn it affects all instances of the service and all its endpoints. This is done by associating the throttle with every channel dispatcher the service uses.Throttling is a hosting and deployment aspect.

When you design a service, make no assumptions about throttling configurationalways assume your service will bear the full brunt of the client's load.

Configuring Throttling:

The following exapmle shows how to configure throttling in the host config file. Using the behaviorConfiguration tag,we add to your service a custom behavior that sets throttled values.

<system.serviceModel>
<services>
<service name = "MyService" behaviorConfiguration = "ThrottledBehavior">
...
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name = "ThrottledBehavior">
<serviceThrottling maxConcurrentCalls  = "100" maxConcurrentSessions  = "454"
           maxConcurrentInstances = "426"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

Reading throttled values:

With the help of service developers for diagnostic and analytical purposes,The throttled values can be read and the service instance can access its throttled properties from its dispatcher at run time

The host base class ServiceHostBase offers the read-only ChannelDispatchers property:

public abstract class ServiceHostBase : CommunicationObject,...
{
   public ChannelDispatcherCollection ChannelDispatchers
   {get;}
   //More members
}

ChannelDispatchers is a strongly typed collection of ChannelDispatcherBase objects:

public class ChannelDispatcherCollection :
SynchronizedCollection<ChannelDispatcherBase>

Throttled Connections in the Binding:

Both the NetTcpBinding and the NetNamedPipeBinding offer the MaxConnections property:When use the TCP and give name-pipe bindings and we can also configure the maximum connection number for a particular endpoint in the binding itself

public class NetTcpBinding : Binding,...
{
   public int MaxConnections 
   {get;set;}
}
public class NetNamedPipeBinding : Binding,...
{
   public int MaxConnections 
   {get;set;}
}

On the host side, you can set that property either programmatically or by using a config file:

<bindings>
<netTcpBinding>
<binding name = "TCPThrottle" MaxConnections  = "25"/>
</netTcpBinding>
</bindings>

MaxConnections defaults to 10. When both a binding-level throttle and a service-behavior throttle sets the max connection value, WCF chooses the lesser of the two.

Previous Home Next