【发布时间】:2011-12-24 12:11:35
【问题描述】:
我的服务主机配置为 10 分钟后关闭连接
<wsHttpBinding>
<binding receiveTimeout="00:10:00">
</wsHttpBinding>
在我的客户端代码中,在使用服务之前,它已经过验证。如果它处于关闭/故障状态,它将创建一个新的。
public static T ValidateService<T>(ref T service) where T : class
{
if (service is IClientChannel)
{
IClientChannel channel = service as IClientChannel;
CommunicationState state = channel.State;
if (state == CommunicationState.Faulted || state == CommunicationState.Closed)
{
// thread safe logic to create new service
}
}
}
问题是当通道在服务器端关闭时,channel.State 仍将返回打开状态。在我进行远程调用后,由于receiveTimeout,我得到了错误异常。
有没有办法让客户端不活动超时?类似于服务器上的receiveTimeout="00:10:00",但少了几秒钟,所以如果不使用我可以很好地关闭客户端的频道,如果需要,我的ValidateService<T> 逻辑将创建一个新频道。
出于性能原因,我不想为每个远程调用创建新通道,因为这些调用可能非常频繁。
我希望避免为我在通信中使用的每项服务设置心跳轮询器。
谢谢
【问题讨论】:
标签: c# wcf timeout wcf-binding