【问题标题】:ClientBase EndPoint Binding SendTimeout ReceiveTimeout: how to change while debuggingClientBase EndPoint Binding SendTimeout ReceiveTimeout:调试时如何更改
【发布时间】:2016-11-11 13:34:49
【问题描述】:

我正在开发一个包含 WCF 服务和使用该服务的客户端的解决方案。有时我在调试服务,有时在调试客户端,有时又在调试两者。

在调试期间,我得到一个带有附加信息的 TimeoutException

附加信息:请求通道在 00:00:59.9950000 之后等待回复时超时。增加传递给 Request 调用的超时值或增加 Binding 上的 SendTimeout 值。分配给此操作的时间可能是较长超时的一部分。

原因当然是我的服务器在断点处等待而不是回答问题。

在调试期间,我想要更长的超时时间,最好不要为我的服务客户端创建新配置,因为如果此配置的其他值发生变化,更改者必须记住创建了一个用于调试的特殊配置。

我认为是这样的:

private IMyServiceInterface CreateServiceChannel()
{
    var myServiceClient = new MyServiceClient(); // reads from configuration file
    if (Debugger.IsAttached)
    {
        // Increase timeouts to enable slow debugging
        ...
    }
    return (IMyServiceInterface)myServiceClient;
}

根据MSDN Binding.SendTimeout Property 用于其他用途:

SendTimeout 获取或设置在传输引发异常之前为完成写操作提供的时间间隔。

因此,如果不需要,我宁愿不更改此值。

  • SendTimeout 真的是增加的最佳超时时间,还是有类似 TransactionTimeout 之类的东西,即我的问题和收到答案之间的超时时间?
  • 如何以编程方式更改超时

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    文章All WCF timouts explained 指出确实存在事务超时之类的东西:IContextChannel.OperationTimeout

    操作超时涵盖整个服务调用(发送请求、处理请求和接收回复)。换句话说,它从客户端的角度定义了服务调用处于活动状态的最长时间。如果未设置,WCF 将使用配置的发送超时初始化操作超时。

    这解释了为什么抛出的 TimeoutException 建议更改发送超时。

    但是,可以在不更改发送超时的情况下更改操作超时:

    var myServiceClient = new MyServiceClient(); // reads from configuration file
    
    if (Debugger.IsAttached)
    {   // Increase timeouts to enable slow debugging:
        IContextChannel contextChannel = (IContextChannel)myServiceClient.InnerChannel;
        // InnerChannel is of type IClientChannel, which implements IContextChannel
    
        // set the operation timeout to a long value, for example 3 minutes:
        contextChannel.OperationTimeout = TimeSpan.FromMinutes(3);
    }
    return (IMyInterface)myService;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2012-05-04
      • 2017-09-22
      • 1970-01-01
      • 2015-05-26
      • 1970-01-01
      • 2020-02-10
      相关资源
      最近更新 更多