Share via


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

屬性值

服務主機接受工作階段的數目上限。 預設值為電腦中的 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 可以接受的通道數目上限。 每個接聽程式物件可以有一個擱置的通道,直到 WCF 接受通道並開始處理訊息為止,才會計入 的值 MaxConcurrentSessions 。 這個屬性在運用工作階段的案例中最為有用。

注意

每當超過這個屬性值時,就會寫入至追蹤。 第一個追蹤會寫入成為警告。

如需會話的詳細資訊,請參閱 使用會話

一般而言,使用 ServiceThrottlingBehavior.MaxConcurrentSessions 屬性便可設定這個屬性。

適用於