Binding.ReceiveTimeout 属性


获取或设置连接在撤消之前保持非活动状态的最大时间间隔,在此时间间隔内未接收任何应用程序消息。Gets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.

 property TimeSpan ReceiveTimeout { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan ReceiveTimeout { get; set; }
member this.ReceiveTimeout : TimeSpan with get, set
Public Property ReceiveTimeout As TimeSpan



用于指定应用程序在超时前必须收到消息的时间长度的 TimeSpan。默认值为10分钟。The TimeSpan that specifies how long the application has to receive a message before timing out. The default value is 10 minutes.


值小于零或太大。The value is less than zero or too large.


使用可靠会话时,必须同时满足两个不同的非活动计时器,才能使连接处于活动状态。When using a reliable session, there are two different inactivity timers that must be satisfied to keep the connection alive. 如果任一非活动计时器结束计时,则将断开连接。If either of these inactivity timers goes off, then the connection is dropped.

  • 第一个非活动计时器为可靠会话计时器,称为 InactivityTimeoutThe first inactivity timer is on the reliable session and is called the InactivityTimeout. 如果在超时期限内没有收到任何应用程序消息或基础结构消息,此非活动计时器将激发。This inactivity timer fires if no messages, either application or infrastructure, are received within the timeout period. 基础结构消息是指为了通道堆栈中的协议之一(例如,保持活动状态或确认,而并非包含应用程序数据)而生成的消息。An infrastructure message is a message that is generated for the purpose of one of the protocols in the channel stack, such as a keep alive or an acknowledgment, rather than containing application data.

  • 第二个非活动计时器为服务计时器,它使用绑定的 ReceiveTimeout 设置。The second inactivity timer is on the service and uses the ReceiveTimeout setting of the binding. 如果在超时期限内没有收到任何应用程序消息,此非活动计时器将激发。This inactivity timer fires if no application messages are received within the timeout period. 例如,它可以指定服务器关闭会话所用的通道前,客户端向服务器发送至少一个消息所需的最长时间。This specifies, for example, the maximum time a client may take to send at least one message to the server before the server will close the channel used by a session. 此行为确保了客户端不能无限期地占用服务器资源。This behavior ensures that clients cannot hold on to server resources for arbitrary long periods.

由于任一非活动计时器激发都会断开连接,因此单纯增大 InactivityTimeout(当其大于 ReceiveTimeout 时)不起任何作用。Since the connection is dropped if either inactivity timer fires, increasing InactivityTimeout once it is greater than ReceiveTimeout has no effect. 这两个超时时间的默认值均为 10 分钟,因此在使用可靠会话时,必须同时增大这两个超时时间才会起作用。The default for both of these timeouts is 10 minutes, so you always have to increase both of them to make a difference when using a reliable session.

如果对绑定或通道启用了事务流,执行操作所需的时间可能会比指定的超时时间长。If transaction flow is enabled on the binding or the channel, the operation may take longer to execute than the specified timeout. 在这些情况下,将会因为超时过期而导致操作失败,事务也将随之中止。In these circumstances the operation fails due to the expired timeout and the transaction aborts appropriately.

如果将安全与会话一起使用,则在绑定上设置的 ReceiveTimeout 值也将用作会话超时。When security is used with sessions, the ReceiveTimeout value set on the binding is also used as the session timeout.