我们最近发现WCF不支持服务端的超时操作(注意,服务端,而不是客户端)。虽然客户端在指定时间后断开连接,但我们的测试表明,对于netNamedPipeBinding、netTcpBinding和basicHttpBinding,我们指定的任何超时都不会导致服务操作在被调用后停止。下面是我们尝试的具体绑定配置:
<bindings>
<netNamedPipeBinding>
<binding name="TestServiceBindingConfigurationNamedPipe"
receiveTimeout="00:00:05"
sendTimeout="00:00:05"
closeTimeout="00:00:05"
openTimeout="00:00:05" />
</netNamedPipeBinding>
<netTcpBinding>
<binding name="TestServiceBindingConfigurationTcp"
receiveTimeout="00:00:05"
sendTimeout="00:00:05"
closeTimeout="00:00:05"
openTimeout="00:00:05" />
</netTcpBinding>
<basicHttpBinding>
<binding name="TestServiceBindingConfigurationBasicHttp"
receiveTimeout="00:00:05"
sendTimeout="00:00:05"
closeTimeout="00:00:05"
openTimeout="00:00:05" />
</basicHttpBinding>
</bindings>
我们的测试服务实现如下所示:
public class TestServiceImpl : ITestService
{
public TestResult TestIt(TestArgs args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
// this is a contrived example, but it shows that WCF never stops this thread
while (true)
{
Console.WriteLine("{0}> I'm running forever...", stopwatch.Elapsed);
}
return new TestResult {Result = "Args were " + args.Args};
}
}
使用netNamedPipeBinding和netTcpBinding,我们的客户端应用程序将在5秒后超时,但服务将无限期地继续运行。
这就引出了我的问题--这是一个bug吗?如果服务运行的时间超过预期,是否有特定的原因使WCF不想让服务超时?
在我看来,与此相关的一些潜在的负面问题包括:
发布于 2011-02-12 06:26:08
我自己也注意到了这个问题。我想不出一个很好的理由为什么他们不把服务端操作超时作为平台的一部分。
发布于 2011-02-12 06:23:27
下面是什么:
<system.web>
<httpRuntime executionTimeout="inSeconds"/>
</system.web>
https://stackoverflow.com/questions/4974640
复制相似问题