请求通道在等待回复时超时

时间:2012-06-26 20:36:52

标签: c# wcf

我有一个小应用程序,它使用WCF与Web服务器通信。该程序由大约200个客户端使用,每个客户端以大约5-20个请求/分钟发送。

查看我经常得到的错误日志:

  

请求频道在等待回复后超时   00:00:59.9989999

请求如下:

ClientService Client = new ClientService();
Client.Open();
Client.updateOnline(userID);
Client.Close();

这是app.config

<configuration>
<configSections>
</configSections>
<startup><supportedRuntime version="v2.0.50727"/></startup><system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IClientService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="PATH TO SERVICE"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClientService"
            contract="IClientService" name="WSHttpBinding_IClientService">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

每天大约200-800的“多次通话”失败。约n-1是好的。我很困惑这个问题是什么。查看服务器统计信息,它几乎没有出汗 - 每个请求都要花费2秒才能处理。它发送的数据包括“int”或“非常小的字符串” - 所以,它不是由于大小,如果是 - 应该有一致的失败..

建议?

3 个答案:

答案 0 :(得分:33)

尝试将超时值添加到服务和客户端:

<binding name="BasicHttpBinding_SomeName" closeTimeout="00:01:00"
    openTimeout="00:01:00" receiveTimeout="00:10:00"
    sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

答案 1 :(得分:10)

似乎您的请求在处理之前在服务器上排队,然后开始超时。你可以在这里尝试几件事来看看究竟发生了什么

1)尝试在WCF服务中进行限制,例如:尝试增加并发会话。看一看 WCF Throttling

2)尝试使用PerCall而不是使用Sessions来确保没有会话。  您可以在界面上执行以下操作来删除会话

[ServiceContract(Namespace="YOUR NAMESPACE", SessionMode=SessionMode.NotAllowed)]

以及实施这些接口的合同类

ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

AND ....您应该启用跟踪以查看到底发生了什么。

答案 2 :(得分:3)

检查此效果计数器 - ASP.NET Requests Queued

一个Web应用程序可以托管许多网页和服务。默认情况下,IIS每个CPU核心仅处理12个并发请求。

这意味着即使您的服务很快但其他页面/服务很慢,您的请求也必须在执行之前等待队列。

ASP.NET Requests Queued应为零或接近于零。

请参阅Performance Counters for ASP.NET on MSDN