gpt4 book ai didi

c# - WCF 在大约 10 次左右的调用后停止响应( throttle )

转载 作者:IT王子 更新时间:2023-10-29 03:59:07 27 4
gpt4 key购买 nike

我有一个 WCF 服务和一个带有对它的服务引用的应用程序,我有一个循环的应用程序,在每次迭代中它都会调用此 wcf 网络服务中的一个方法。

问题是在大约 9 次调用之后,它就停止了......如果你点击 VS 的 Pause 按钮,你会看到它卡在调用的那一行.

等待一段时间后,抛出此TimeoutException:

The request channel timed out while waiting for a reply after 00:00:59.9970000. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.


我对此进行了一些研究,发现了一些涉及在应用程序中编辑 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>

[更新]解决方案:

显然,在每次请求后您必须关闭连接...我现在在每次请求后关闭连接并且它的工作就像一个魅力。

虽然我仍然无法理解的是,在我的 app.config 中,我将 maxConcurrentCalls 和 maxConcurrentSessions 设置为 500,但是,我只能做 10 个。任何人对此都有任何答案? (也许我在上面发布的 app.config 中有问题)

上述问题的答案(现在是虚线)是因为我正在编辑客户端 app.config,而不是服务配置文件 (web.config)

最佳答案

默认允许的并发连接数为10。
您的客户端很可能没有关闭连接。

要增加并发调用的数量,您必须将您的行为添加到服务配置中,而不是客户端。

关于c# - WCF 在大约 10 次左右的调用后停止响应( throttle ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/739312/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com