WCF 错误 - 系统达到了为限制“MaxConcurrentSessions”设置的限制

发布于 2024-10-13 01:34:37 字数 892 浏览 2 评论 0 原文

我有一个调用 WCF 服务的 asp.net 应用程序。我已经间歇性超时一段时间了,所以我决定创建一个跟踪日志。超时后,我在日志文件中发现了以下消息:

系统达到了设定的限制 限制“MaxConcurrentSessions”。 此油门的限制设置为 10。 油门值可以通过以下方式更改 修改属性 'maxConcurrentSessions' 在 服务油门元件或通过 修改“最大并发会话数” 行为属性 服务节流行为。

问题是,虽然我每次都会关闭客户端连接,所以我不明白为什么并发会话会增加。下面是我进行的一个典型调用:

    try
    {
        //create proxy
        client = new CAEServiceContractClient();

        response = client.GetSecurityRecords(item); 
        totalRecords = response.TotalRecords;

        securityListView.DataSource = response.SecurityItemColl; 
        securityListView.DataBind();

        // Always close the client.
        client.Close();
        success = true;
    }
    finally
    {
        if (!success)
        {
            client.Abort();
        }
    }

所以我的问题是,为什么在我执行 client.Close() 后会话没有被销毁?

TIA。

I have an asp.net app that calls a WCF service. I've been having intermittent timeouts for a while so I decided to create a trace log. After getting a timeout I found the message below in the log file:

The system hit the limit set for
throttle 'MaxConcurrentSessions'.
Limit for this throttle was set to 10.
Throttle value can be changed by
modifying attribute
'maxConcurrentSessions' in
serviceThrottle element or by
modifying 'MaxConcurrentSessions'
property on behavior
ServiceThrottlingBehavior.

The thing is though I'm closing the client connection each time so I don't understand why the concurrent sessions are adding up. Below is a typical call that I make:

    try
    {
        //create proxy
        client = new CAEServiceContractClient();

        response = client.GetSecurityRecords(item); 
        totalRecords = response.TotalRecords;

        securityListView.DataSource = response.SecurityItemColl; 
        securityListView.DataBind();

        // Always close the client.
        client.Close();
        success = true;
    }
    finally
    {
        if (!success)
        {
            client.Abort();
        }
    }

So my question is, why isn't the session being destroyed once I execute client.Close()?

TIA.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-20 01:34:37

我没有看到上面代码中将 success 声明为局部变量,也没有看到您将其设置为 false。它是否可能是一个类成员在第一次成功调用时被设置为 true ,然后保持这种状态?

在任何情况下,整个代码块都可以重写为更容易理解(并且不易出现错误),如下所示:

using (var client = new CAEServiceContractClient())
{
    response = client.GetSecurityRecords(item); 
    totalRecords = response.TotalRecords;

    securityListView.DataSource = response.SecurityItemColl; 
    securityListView.DataBind();
}

using 语句确保当 using 块具有完成(正常或因异常而异常),client 变量将被释放(.Dispose() 将被调用),从而关闭连接。

编辑: 正如 Ladislav Mrnka 指出的,ClientBase.Dispose() 方法有一个在某些情况下抛出异常的坏习惯。确保按照 CAEServiceContractClient 类中实现 .Dispose() 方法这是 wcf-client-using-block-issue/1424384#1424384">此处的最佳解决方法

I don't see success declared in the above code as a local variable, nor do I see you setting it to false. Could it be a class member that is being set to true on the first successful call and then staying that way?

In any case, that whole code block can be rewritten to be simpler to understand (and less bug-prone) like this:

using (var client = new CAEServiceContractClient())
{
    response = client.GetSecurityRecords(item); 
    totalRecords = response.TotalRecords;

    securityListView.DataSource = response.SecurityItemColl; 
    securityListView.DataBind();
}

The using statement ensures that when the using block has completed (normally or abnormally by an exception), the client variable will be disposed (.Dispose() will be called), thus closing the connection.

EDIT: As Ladislav Mrnka pointed out, the .Dispose() method of ClientBase has a bad habit of throwing an exception in some cases. Make sure to implement the .Dispose() method in your partial CAEServiceContractClient class as described here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文