是否可以通过Wcftest客户端测试WCF限制行为?

sha*_*ond 5 .net c# wcf throttling

是否可以通过Wcftest客户端测试WCF限制行为?

如果是,那么如何?

我在ServiceHost下面有一个代码

 ServiceThrottlingBehavior stb = _servicehost.Description.Behaviors.Find<ServiceThrottlingBehavior>();
        if (stb == null)
        {
            stb = new ServiceThrottlingBehavior();
            stb.MaxConcurrentCalls = 1;
            stb.MaxConcurrentInstances = 1;
            stb.MaxConcurrentSessions = 1;
            _servicehost.Description.Behaviors.Add(stb);
        }
Run Code Online (Sandbox Code Playgroud)

我的服务有一个方法,如:

    public string ThrottlingCheck()
    {
        Thread.Sleep(new TimeSpan(0, 0, 0, 5, 0));//5 seconds
        return "Invoke Complete";
    }
Run Code Online (Sandbox Code Playgroud)

Cyb*_*axs 2

由于您的请求需要 5 秒,因此您可以通过使用两个 WCF 测试客户端同时调用两个操作或在同一 WCF 客户端中打开两个选项卡来轻松测试这一点。

集成测试无疑是检查此行为的更好选择。

此外,如果您想检查该行为是否确实应用于您的服务,您可以使用 WCF 诊断,例如 WCF 计数器,尤其是“最大并发 XXX 的百分比”。

在此输入图像描述