首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么WCF不支持服务端超时?

为什么WCF不支持服务端超时?
EN

Stack Overflow用户
提问于 2011-02-12 06:17:43
回答 2查看 3.1K关注 0票数 21

我们最近发现WCF不支持服务端的超时操作(注意,服务端,而不是客户端)。虽然客户端在指定时间后断开连接,但我们的测试表明,对于netNamedPipeBinding、netTcpBinding和basicHttpBinding,我们指定的任何超时都不会导致服务操作在被调用后停止。下面是我们尝试的具体绑定配置:

代码语言:javascript
复制
<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>

我们的测试服务实现如下所示:

代码语言:javascript
复制
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不想让服务超时?

在我看来,与此相关的一些潜在的负面问题包括:

  1. 服务实例的默认限制是10。因此,如果您的服务中有永远运行的错误代码,并且它被命中10次,则您的服务将完全关闭;没有新的连接accepted.
  2. There无法看到服务将永远运行的事实-缺少自定义日志记录或可能使用性能计数器
  3. 服务调用正在使用的任何资源(例如,SQL行、页和表锁),如果没有其他机制使操作超时,则可能会无限期地保持。
EN

回答 2

Stack Overflow用户

发布于 2011-02-12 06:26:08

我自己也注意到了这个问题。我想不出一个很好的理由为什么他们不把服务端操作超时作为平台的一部分。

票数 2
EN

Stack Overflow用户

发布于 2011-02-12 06:23:27

下面是什么:

代码语言:javascript
复制
<system.web>
    <httpRuntime executionTimeout="inSeconds"/>
</system.web>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4974640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档