gpt4 book ai didi

c# - ClientBase 端点绑定(bind) SendTimeout ReceiveTimeout : how to change while debugging

转载 作者:行者123 更新时间:2023-11-30 23:18:55 25 4
gpt4 key购买 nike

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

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

附加信息:请求 channel 在 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 gets or sets the interval of time provided for a write operation to complete before the transport raises an exception.

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

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

最佳答案

文章All WCF timouts explained指出确实存在类似事务超时的情况:IContextChannel.OperationTimeout

The operation timeout covers the whole service call (sending the request, processing it and receiving a reply). In other words, it defines the maximum time a service call is active from a client’s point of view. If not set, WCF initializes the operation timeout with the configured send timeout.

这解释了为什么抛出的 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;

关于c# - ClientBase 端点绑定(bind) SendTimeout ReceiveTimeout : how to change while debugging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40549144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com