WCF 未正确超时?
我遇到超时问题,这些是详细信息:
我的绑定配置如下所示:
<netTcpBinding>
<binding name="WindowsServerOverTcp"
maxReceivedMessageSize="10000000"
maxBufferSize="10000000"
maxBufferPoolSize="10000000"
closeTimeout="00:00:03"
openTimeout="00:00:03"
sendTimeout="00:00:03"
receiveTimeout="00:00:03">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</netTcpBinding>
我正在向服务器发送一条消息,我知道该服务器已关闭,因此连接应该按照我的 app.config 中的规定在 3 秒后超时,但由于某种原因需要 20-30 秒。
当 EndPointNotFoundException 抛出时,这是我得到的信息:
System.ServiceModel.EndPointNotFoundException: 无法连接到 net.tcp://10.0.0.82:4466/MegaMatcherWcf。 连接尝试持续了 时间跨度为 00:00:03。 TCP错误代码 10060:连接尝试失败 因为关联方没有 一段时间后正确应对 时间,或建立的连接失败 因为连接的主机未能 响应10.0.0.82:4466
如果我在机器打开的情况下尝试相同的测试,但没有运行监听软件,我会得到预期的行为,连接在 3 秒后超时。为什么机器关机后需要30秒,然后告诉我花了3秒?
I am having a timeout issue, these are the details:
My binding configuration looks like this:
<netTcpBinding>
<binding name="WindowsServerOverTcp"
maxReceivedMessageSize="10000000"
maxBufferSize="10000000"
maxBufferPoolSize="10000000"
closeTimeout="00:00:03"
openTimeout="00:00:03"
sendTimeout="00:00:03"
receiveTimeout="00:00:03">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</netTcpBinding>
I am sending a message to a server which I know is turned off so the connection should just time out after 3 seconds as stipulated in my app.config, but for some reason it is taking 20-30 seconds.
When the EndPointNotFoundException is thrown this is the info I get:
System.ServiceModel.EndPointNotFoundException:
Could not connect to
net.tcp://10.0.0.82:4466/MegaMatcherWcf.
The connection attempt lasted for a
time span of 00:00:03. TCP error code
10060: A connection attempt failed
because the connected party did not
properly respond after a period of
time, or established connection failed
because connected host has failed to
respond 10.0.0.82:4466
If I try the same test with the machine turned on, but no listening software running I get the expected behaviour, with the connection timing out after 3 seconds. Why if the machine is off does it take 30 seconds, and then tell me it took 3 seconds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
比@BiggsSTRC(其答案大致正确)更具体一点:
System.Net.Sockets
类建立传输层连接
NetTcpBinding 通道;
System.Net.Sockets
是非托管 WINSOCK API 的包装器;WSAConnect()
,.NETSocket.Connect()
方法使用;System.ServiceModel.Channels.SocketConnectionInitiator.Connect()
中)调用Socket.Connect
,如果抛出某些类型的异常,它会检查以查看连接超时时间是否还有剩余时间。如果不存在,您将收到EndpointNotFoundException
以及您所看到的错误消息;ElapsedTime
的方法,但这是一个用词不当,因为它永远不会返回大于原始超时时间的值:这就是错误消息向您谎报连接尝试花费多长时间的原因。WCF 可以通过使用 Sockets API 的异步方法来强制其配置的超时,监视连接尝试的单独线程上的超时,但目前还没有这样做。如果您认为这是一个错误(可以说确实如此),您可以在 Microsoft 的 Connect 站点 上报告它,也许将来会修复它版本或服务包。
To be a bit more specific than @BiggsTRC (whose answer is broadly correct):
System.Net.Sockets
classes the details ofestablishing the transport layer connection in
a NetTcpBinding channel;
System.Net.Sockets
is a wrapper around the unmanaged WINSOCK API;WSAConnect()
, which the .NETSocket.Connect()
method uses;System.ServiceModel.Channels.SocketConnectionInitiator.Connect()
) callsSocket.Connect
, and if this throws an exception of certain types, it checks to see whether there is any remaining time in its connection timeout period. If there isn't, you get anEndpointNotFoundException
with the error message you have seen;TimeoutHelper
class to keep track of timeout periods and do the time arithmetic. This has a method calledElapsedTime
, but this is a misnomer since it never returns a value greater than the original timeout period: that is the reason the error message lies to you about how long the connection attempt took.WCF could enforce its configured timeouts by using the asynchronous methods of the Sockets API, monitoring the timeout on a separate thread to the connect attempt, but it does not currently do so. If you think this is a bug (which arguably it is) you could report it on Microsoft's Connect Site and perhaps get it fixed in a future version or service pack.
我相信您现在正在处理 Windows 超时问题,而不是 WCF 超时问题。 Windows 将花费 20-30 秒的时间来确定计算机在网络上没有响应。当您调用 WCF 服务器时,Windows 首先必须建立到该服务器的路由。当它不能时,它会警告您的软件,并且您的软件认为它已达到自己的超时时间。您的系统永远不会真正轮询该服务是否正在运行,因为 Windows 仍在尝试在该 IP 地址的另一端查找某些内容。
I believe you are dealing with a Windows timeout issue now, not your WCF timeout. Windows will take 20-30 seconds to determine that a machine is not responding on the network. When you make your call to the WCF server, Windows first has to establish a route to the server. When it can't, it alerts your software and your software thinks that it reached its own timeout. Your system never gets to the point of actually polling to see if the service is running because Windows is still trying to find something at the other end of that IP address.
我遇到了同样的问题
,做了所有的事情,尝试了所有的配置,但没有任何帮助。
互联网上的 net.tcp 在冗长的进程中超时了,
唯一对我有帮助的是当我使用
https://msdn.microsoft.com/en-我们/library/ff395349.aspx
I was facing the same problem
Did every thing, tried every configuration nothing helped.
net.tcp over internet is timing out like hell on lengthy processes
the only thing that helped me is when i used
https://msdn.microsoft.com/en-us/library/ff395349.aspx