WCF 未正确超时?

发布于 2024-11-06 16:01:13 字数 1084 浏览 3 评论 0原文

我遇到超时问题,这些是详细信息:

我的绑定配置如下所示:

<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 技术交流群。

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

发布评论

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

评论(3

触ぅ动初心 2024-11-13 16:01:13

比@BiggsSTRC(其答案大致正确)更具体一点:

  • WCF 将以下详细信息委托给 System.Net.Sockets
    建立传输层连接
    NetTcpBinding 通道;
  • System.Net.Sockets 是非托管 WINSOCK API 的包装器;
  • WINSOCK API 具有内部默认超时,但不提供任何记录的机制来指定某些阻塞操作的超时,包括 WSAConnect(),.NET Socket.Connect() 方法使用;
  • WCF 代码(在 System.ServiceModel.Channels.SocketConnectionInitiator.Connect() 中)调用 Socket.Connect,如果抛出某些类型的异常,它会检查以查看连接超时时间是否还有剩余时间。如果不存在,您将收到 EndpointNotFoundException 以及您所看到的错误消息;
  • WCF 使用 TimeoutHelper 类来跟踪超时周期并进行时间算术。它有一个名为 ElapsedTime 的方法,但这是一个用词不当,因为它永远不会返回大于原始超时时间的值:这就是错误消息向您谎报连接尝试花费多长时间的原因。

WCF 可以通过使用 Sockets API 的异步方法来强制其配置的超时,监视连接尝试的单独线程上的超时,但目前还没有这样做。如果您认为这是一个错误(可以说确实如此),您可以在 Microsoft 的 Connect 站点 上报告它,也许将来会修复它版本或服务包。

To be a bit more specific than @BiggsTRC (whose answer is broadly correct):

  • WCF delegates to the System.Net.Sockets classes the details of
    establishing the transport layer connection in
    a NetTcpBinding channel;
  • System.Net.Sockets is a wrapper around the unmanaged WINSOCK API;
  • The WINSOCK API has internal default timeouts but does not provide any documented mechanism for specifying a timeout on certain blocking operations, including WSAConnect(), which the .NET Socket.Connect() method uses;
  • The WCF code (in System.ServiceModel.Channels.SocketConnectionInitiator.Connect()) calls Socket.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 an EndpointNotFoundException with the error message you have seen;
  • WCF uses a TimeoutHelper class to keep track of timeout periods and do the time arithmetic. This has a method called ElapsedTime, 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.

断爱 2024-11-13 16:01:13

我相信您现在正在处理 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.

迷爱 2024-11-13 16:01:13

我遇到了同样的问题

,做了所有的事情,尝试了所有的配置,但没有任何帮助。

互联网上的 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

Duplex or Callback Message Exchange Pattern

https://msdn.microsoft.com/en-us/library/ff395349.aspx

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