我有一个 WCF 服务和一个带有对它的服务引用的应用程序,并且对于该应用程序,我有一个循环,并且在每次迭代中,它都会调用这个 wcf web 服务中的一个方法。
问题是在大约 9 次调用之后,它就停止了……如果你Pause
按下 VS 的按钮,你会看到它卡在它发出调用的线路上。
在等待一段时间后,会抛出这个TimeoutException :
请求通道在 00:00:59.9970000 之后等待回复时超时。增加传递给 Request 调用的超时值或增加 Binding 上的 SendTimeout 值。分配给此操作的时间可能是较长超时的一部分。
我对此进行了一些研究,发现了一些涉及在应用程序中编辑 app.config 的解决方案,以下是其中的摘录:
<serviceBehaviors>
<behavior name="ThrottlingIssue">
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" />
</behavior>
</serviceBehaviors>
.
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
然后,在我停止调试后,几分钟后,会弹出一条错误消息,告诉我发生了灾难性故障。
我该如何解决这个问题?当我使用普通的 Web 服务时,我没有遇到这个问题。
供参考,这里是整个app.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ThrottlingIssue">
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDBInteractionGateway" 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="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:28918/DBInteractionGateway.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDBInteractionGateway"
contract="DBInteraction.IDBInteractionGateway" name="WSHttpBinding_IDBInteractionGateway">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
[更新] 解决方法:
显然,在每次请求之后你必须Close
连接......我现在在每次请求后关闭连接,它的工作就像一个魅力。
虽然我仍然无法理解的是,在我的 app.config 中,我将 maxConcurrentCalls 和 maxConcurrentSessions 设置为 500,但我只能设置 10。任何人对此有任何答案吗?(也许我在上面发布的 app.config 中有问题)
上述问题的答案(现在用虚线表示)是因为我正在编辑客户端app.config
,而不是服务配置文件(web.config
)