最後我做到了。 在這裏,我張貼我的解決方案,可能是新的WCF請求排隊的其他用戶。 首先,我們需要在WCF主機文件中實施限制設置。 節流可以通過兩種方式來完成(無論哪種方式是OK):
- 配置文件
- 代碼
在配置文件限制設置如下:
[行爲] [serviceBehaviors] [behavior name =「throttlingBehavior」] [serviceThrottling maxConcurrentCalls =「3」maxConcurrentInstances =「3」maxConcurrentSessions =「100」/] [/ behavior] [/ serviceBehaviors] [/行爲]在代碼
using (ServiceHost host = new ServiceHost(typeof(SimpleService.SimpleService)))
{
ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = 3, MaxConcurrentInstances = 3, MaxConcurrentSessions = 100 };
host.Description.Behaviors.Add(throttlingBehavior);
host.Open();
Console.WriteLine("Host started @ " + DateTime.Now.ToString());
Console.ReadLine();
}
利用上述限制設置最多3個併發呼叫被處理
或者限制設置。除了maxConcurrentCalls屬性,maxConcurrentInstances和maxConcurrentSessions也可能影響併發處理的呼叫數。
現在定義限制行爲後,我們需要在服務合同定義併發模式如下:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Multiple)]
public class Service:IService
{...
隨着放置這些設置,我們可以很容易地獲得請求的WCF服務排隊。
謝謝你的問題,雖然我已經標記了它:問題要求我們推薦或找到一個教程是堆棧溢出題外話,因爲他們傾向於吸引輿論的答案和垃圾郵件。相反,請描述問題以及到目前爲止解決問題所做的工作。 –