ServiceThrottle.MaxConcurrentSessions 属性

定义

获取或设置一个指定 ServiceHost 对象可一次接受的最大会话数的值。

public:
 property int MaxConcurrentSessions { int get(); void set(int value); };
public int MaxConcurrentSessions { get; set; }
member this.MaxConcurrentSessions : int with get, set
Public Property MaxConcurrentSessions As Integer

属性值

Int32

服务主机可接受的最大会话数。 默认值为计算机中的处理器数 100 * 。

示例

下面的代码示例通过引用应用程序配置文件中的 ServiceThrottle,演示了 ServiceThrottlingBehavior 的典型用法。 在这种情况下,对于一个到 InstanceContext 的连接,指定的值一次最多只能建立一个消息处理。 实际的用法必须根据经验确定。

<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>

注解

MaxConcurrentSessions 属性指定 ServiceHost 可接受的最大通道数。 每个侦听器对象可以有一个挂起的 MaxConcurrentSessions 通道,在 WCF 接受通道并开始处理消息之前,不会计入其值。 在使用会话的方案中,此属性是最有用的。

备注

此属性的值超出限制一次,就会记录一个跟踪。 第一个跟踪将记录为警告。

有关会话的详细信息,请参阅使用会话

通常,此属性是通过使用 ServiceThrottlingBehavior.MaxConcurrentSessions 属性来设置的。

适用于