Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么TimeoutException不会影响我的频道?_C#_.net_Wcf_Duplex_Timeoutexception - Fatal编程技术网

C# 为什么TimeoutException不会影响我的频道?

C# 为什么TimeoutException不会影响我的频道?,c#,.net,wcf,duplex,timeoutexception,C#,.net,Wcf,Duplex,Timeoutexception,我有一个双工WCF服务和客户端在同一台机器上运行。客户端配置为有15秒超时: <binding name="NetTcpBinding_IServiceIPC" closeTimeout="00:00:15" openTimeout="00:00:15" receiveTimeout="00:00:15" sendTimeout="00:00:15" /> 如果我终止服务进程,客户端将在15秒后正确获得TimeoutException: This request ope

我有一个双工WCF服务和客户端在同一台机器上运行。客户端配置为有15秒超时:

<binding name="NetTcpBinding_IServiceIPC" closeTimeout="00:00:15"
      openTimeout="00:00:15" receiveTimeout="00:00:15" sendTimeout="00:00:15" />
如果我终止服务进程,客户端将在15秒后正确获得
TimeoutException

This request operation sent to net.tcp://localhost:8732/Service/ did not receive a reply within the configured timeout (00:00:15).  The time allotted to this operation may have been a portion of a longer timeout.  This may be because the service is still processing the operation or because the service was unable to send a reply message.  Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client. (System.TimeoutException)
但是,此时通道未出现故障。我的故障处理程序直到我终止服务进程大约5分钟后才被调用。我原以为
TimeoutException
会导致频道出现故障(参见此),但不知何故,情况似乎并非如此。是否有任何方法可以在服务进程终止后更快地强制通道出现故障?

此问题表明并非总是触发
故障事件。MSDN上的WCF状态流程图证实了以下可能性-


有许多通向关闭状态的路径不经过故障状态。最有可能的情况是,当您超时时,将调用
Abort()
方法,您将从打开状态转换到关闭状态,而不会经历故障状态。添加一些日志以检查整个执行过程中的状态。如果您试图在超时后重新打开通道,这可以解释为什么您在5分钟后进入故障状态。要解决更大的问题,请将
FaultedHandler
中的逻辑移到其他位置,以便在通过其他路径达到关闭状态时执行它。

我知道这个问题已经过时了。但我找了很多,最后总是在这里。所以我想把我的发现贴在这里:

这取决于哪个超时

如果点击绑定的
SendTimeout
ReceiveTimeout
(在我的例子中是
NetTcpBinding
),则是,通道将出现故障


但是,如果您点击服务的
操作超时
(在我的例子中是DuplexChannel),那么您只会得到一个
TimeoutException
,而该频道将出现故障。

顺便说一句,当我的服务被终止时,该频道没有出现故障,因为该服务启动了一个不相关的可执行文件,并且只要该进程在运行,该通道就会以某种方式保持打开状态。
This request operation sent to net.tcp://localhost:8732/Service/ did not receive a reply within the configured timeout (00:00:15).  The time allotted to this operation may have been a portion of a longer timeout.  This may be because the service is still processing the operation or because the service was unable to send a reply message.  Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client. (System.TimeoutException)