2009-04-27 6 views
4

私は私のWCFサービスServiceClientのインスタンスをバック返すために、以下のコードを持っている:最近、私はタイムアウトを持ついくつかの問題を持っていたので、私はスロットリング動作を追加することを決定し、そのようようWCF:ServiceThrottlingBehaviorをWCFサービスに追加するにはどうすればよいですか?

var readerQuotas = new XmlDictionaryReaderQuotas() 
    { 
     MaxDepth = 6000000, 
     MaxStringContentLength = 6000000, 
     MaxArrayLength = 6000000, 
     MaxBytesPerRead = 6000000, 
     MaxNameTableCharCount = 6000000 
    }; 


    var throttlingBehaviour = new ServiceThrottlingBehavior(){MaxConcurrentCalls=500,MaxConcurrentInstances=500,MaxConcurrentSessions = 500}; 
    binding = new WSHttpBinding(SecurityMode.None) {MaxReceivedMessageSize = 6000000, ReaderQuotas = readerQuotas}; 

    dualBinding = new WSDualHttpBinding(WSDualHttpSecurityMode.None) 
         {MaxReceivedMessageSize = 6000000, ReaderQuotas = readerQuotas}; 

    endpointAddress = new EndpointAddress("http://localhost:28666/DBInteractionGateway.svc"); 

    return new MusicRepo_DBAccess_ServiceClient(new InstanceContext(instanceContext), dualBinding, endpointAddress); 

を:

var throttlingBehaviour = new ServiceThrottlingBehavior() { 
     MaxConcurrentCalls=500, 
     MaxConcurrentInstances=500, 
     MaxConcurrentSessions = 500 
    }; 

私の質問は、上記のコードで私はこのthrottlingBehaviourを私のMusicRepo_DBAccess_ServiceClientインスタンスに追加すべきですか?私はないです一方、上記のコードでは、彼らはServiceHostを使用していることを

ServiceHost host = new ServiceHost(typeof(MyService)); 
ServiceThrottlingBehavior throttleBehavior = new ServiceThrottlingBehavior 
{ 
    MaxConcurrentCalls = 40, 
    MaxConcurrentInstances = 20, 
    MaxConcurrentSessions = 20, 
}; 
host.Description.Behaviors.Add(throttleBehavior); 
host.Open(); 

お知らせ、そして:私はウェブ上で発見例の一部から


は、彼らがこのような何かをやっています彼らはMusicRepo_DBAccess_ServiceClientインスタンスを開いている間に(Open()と)それを開いています...そして、これが私を混乱させました。

+0

は、設定ファイルでこれを持っていないことはできますか? – rguerreiro

+0

私はこのwcfサービスをapp.configファイルを持たない複数のプロジェクトと共有する必要があります。そのため、私は設定をプログラムで構築しています。 –

+0

サービスのホスティングはどこですか? – rguerreiro

答えて

3

設定ファイルafaikで動作を指定でき、生成されたクライアントは動作を使用して従います。

スロットリングは、サービス側で簡潔

<service 
    behaviorConfiguration="throttleThis" /> 

     <serviceBehaviors> 
      <behavior name="throttleThis"> 
       <serviceMetadata httpGetEnabled="True" /> 
       <serviceThrottling 
        maxConcurrentCalls="40" 
        maxConcurrentInstances="20" 
        maxConcurrentSessions="20"/> 
      </behavior> 
     </serviceBehaviors> 
6

除外一部の構成セクション(サーバー)の動作ではありません、クライアント側1

アーノン

+0

コード化されていない設定が必要ですか? – FaizanRabbani

17

は、私のようなもののためのコードで行うことができます誰が実行時に設定します。

VBのバージョン:

Dim stb As New ServiceThrottlingBehavior 
    stb.MaxConcurrentSessions = 100 
    stb.MaxConcurrentCalls = 100 
    stb.MaxConcurrentInstances = 100 
    ServiceHost.Description.Behaviors.Add(stb) 

C#バージョン:

ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior { 
     MaxConcurrentSessions = 100, 
     MaxConcurrentCalls = 100, 
     MaxConcurrentInstances = 100 
    }; 
    ServiceHost.Description.Behaviors.Add(stb); 
関連する問題