2012-01-19 11 views
2

私はWCF経由でWebサービスを消費しています。サービスメソッド呼び出しを毎秒N回制限したいとします。私がこれを達成するのを助けるクラスがありますか?または手動でカウントを更新して毎秒リセットする必要がありますか?調整 - 1秒あたりの最大メソッド呼び出し

+0

クライアント、サーバー、またはその両方でスロットルしたいですか? WCF Webサービスを使用する際のオーバーヘッドの多くは、シリアライズとコールの処理にあります。あなたがパフォーマンスを向上させるためにこれをやっているのであれば、気をつけておいてください。 – Yuck

+0

Webサービスを使用するWCFサービスを作成しているのですか、WCF経由でWebサービスにアクセスしていますか?サービスをローリングしている場合、WCFサービスのスロットル設定を設定することで、効果的にWebサービスへの呼び出しを抑制できます。あなたがWebサービスを消費しているだけの場合は、独自のカウンタメカニズムを作成しているかもしれないと思います。 –

+0

このようなスロットルでは何を防止しようとしていますか?タイムスロットルや充電モデル自体があるリソースを消費していますか? –

答えて

1

これは、あなたがコード内の絞り方法で構築使用することができます

http://www.danrigsby.com/blog/index.php/2008/02/20/how-to-throttle-a-wcf-service-help-prevent-dos-attacks-and-maintain-wcf-scalability/

を絞るに役立つ記事です:

ServiceHost host = new ServiceHost(
typeof(MyContract), 
new Uri("http://localhost:8080/MyContract")); 
host.AddServiceEndpoint("IMyContract", new WSHttpBinding(), ""); 
System.ServiceModel.Description.ServiceThrottlingBehavior throttlingBehavior = 
new System.ServiceModel.Description.ServiceThrottlingBehavior(); 
throttlingBehavior.MaxConcurrentCalls = 16; 
throttlingBehavior.MaxConcurrentInstances = Int32.MaxValue; 
throttlingBehavior.MaxConcurrentSessions = 10; 
host.Description.Behaviors.Add(throttlingBehavior); 
host.Open(); 

またはweb.configファイルにそれらを置く:

<system.serviceModel> 
<services> 
    <service 
     name="IMyContract" 
     behaviorConfiguration="myContract"> 
     <host> 
      <baseAddresses> 
       <add baseAddress="http://localhost:8080/MyContract"/> 
      </baseAddresses> 
     </host> 
     <endpoint 
      name="wsHttp" 
      address="" 
      binding="wsHttpBinding" 
      contract="IMyContract"> 
     </endpoint> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
     <behavior name="myContract"> 
      <serviceMetadata httpGetEnabled="True" /> 
      <serviceThrottling 
       maxConcurrentCalls="16" 
       maxConcurrentInstances="2147483647" 
       maxConcurrentSessions="10"/> 
     </behavior> 
    </serviceBehaviors> 
</behaviors> 

関連する問題