Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
WCF Feature Details
Contracts
 Using ServiceThrottlingBehavior to ...

  Switch on low bandwidth view
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Using ServiceThrottlingBehavior to Control WCF Service Performance

The ServiceThrottlingBehavior class exposes properties that can be used to limit how many instances or sessions are created at the application level. Using this behavior you can fine-tune the performance of your Windows Communication Foundation (WCF) application.

Controlling Service Instances and Concurrent Calls

Use the MaxConcurrentCalls property to specify the maximum number of messages actively processing across a ServiceHost object, and the MaxConcurrentInstances property to specify the maximum number of InstanceContext objects in the service.

Because determining the settings for these properties usually takes place after real-world experience running the application against loads, the settings for the ServiceThrottlingBehavior properties is typically specified in an application configuration file using the throttling element.

The following code example shows the use of ServiceThrottlingBehavior from an application configuration file that sets the MaxConcurrentSessions, MaxConcurrentCalls, and MaxConcurrentInstances properties to 1 as a trivial example. Real-world experience determines the optimal settings for any particular application.

Xml
<configuration>
  <appSettings>
    <!-- use appSetting to configure base address provided by host -->
    <add key="baseAddress" value="http://localhost:8080/ServiceMetadata" />
  </appSettings>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="Throttled" >
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService"/>
          </baseAddresses>
        </host>
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.WCF.Documentation.ISampleService"
         />
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange"
         />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior  name="Throttled">
          <serviceThrottling 
            maxConcurrentCalls="1" 
            maxConcurrentSessions="1" 
            maxConcurrentInstances="1"
          />
          <serviceMetadata 
            httpGetEnabled="true" 
            httpGetUrl=""
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The exact runtime behavior depends upon the values of the ConcurrencyMode and InstanceContextMode properties, which control how many messages can execute inside an operation at once and the lifetimes of the service InstanceContext relative to incoming channel sessions, respectively.

For details, see the MaxConcurrentCalls, and MaxConcurrentInstances properties.

See Also

Footer image

Send comments about this topic to Microsoft.
© Microsoft Corporation. All rights reserved.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker