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

プロパティ値

1 つのサービス ホストが受け入れ可能なセッションの最大数。 既定値はプロセッサ数の 100 倍です。

例として、ServiceThrottlingBehaviorMaxConcurrentSessions、および MaxConcurrentCalls の各プロパティを 1 に設定するアプリケーション構成ファイルから MaxConcurrentInstances を使用する方法を次のコード例に示します。 特定のアプリケーションで最適な設定については、実際の動作から判断します。

<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 オブジェクトが受け入れ可能なセッションの最大数を表します。 この場合のセッションは、信頼できるセッションをサポートしているチャネルだけを意味するわけではないことに注意してください (たとえば、System.ServiceModel.NetNamedPipeBinding はセッションをサポートしますが、信頼できるセッションは含みません)。

各リスナー オブジェクトには、WCF がチャネル セッションを受け入れてメッセージの処理を開始するまで、 の値に対してカウントされない保留中の MaxConcurrentSessions チャネル セッションを 1 つ含めることができます。 このプロパティは、セッションを使用するシナリオで最も有用です。

このプロパティをクライアントのスレッド数より少ない値に設定すると、複数のクライアントからの要求が同じソケット接続でキューに置かれる場合があります。 このサービスで開いているセッション数が MaxConcurrentSessions に達している場合、このサービスでセッションを作成していないクライアントからの要求は、他のクライアントとのセッションが閉じられるまでブロックされます。 処理されないクライアント要求はタイムアウトになり、セッションが突然閉じられます。

この状況を回避するには、別のアプリケーション ドメインからクライアント スレッドを実行して、要求メッセージが別のソケット接続に送信されるようにします。

アプリケーション構成ファイルで serviceThrottling> 要素を<使用して、この属性の値を設定することもできます。

適用対象