ClientBase EndPoint Binding SendTimeout ReceiveTimeout:调试时如何

本文关键字:调试 ReceiveTimeout EndPoint Binding SendTimeout ClientBase | 更新日期: 2023-09-27 18:17:22

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

在调试过程中,我得到一个TimeoutException和附加信息

附加信息:在等待00:00:59.9950000之后的应答时,请求通道超时。增加传递给请求调用的超时值或增加绑定上的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绑定。SendTimeout属性用于其他内容:

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

因此,如果不需要,我宁愿不改变这个值。

    SendTimeout真的是最好的超时增加,或者有一个像TransactionTimeout,我的问题和收到的答案之间的超时?
  • 如何以编程方式更改超时

ClientBase EndPoint Binding SendTimeout ReceiveTimeout:调试时如何

文章All WCF timeout解释了确实存在类似事务超时的东西: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;