在客户端,我处理代理状态,以便当它的 State==CommunicationState.Faulted 时,它会自动调用 Abort() 并优雅地转换到 CommunicationState.Closed。在服务器端,我有 2 个事件连接到回调通道
OperationContext.Current.Channel.Faulted += Channel_Faulted;
OperationContext.Current.Channel.Closed += Channel_Closed;
这是我的活动代码
private void Channel_Closed(object sender, EventArgs e)
{
var callback = sender as IPtiCommunicationCallback;
PtiClient client;
lock (syncObj)
{
client = clientsList.FirstOrDefault(x => x.Value == callback).Key;
}
if (client != null)
{
//Code to remove client from the list
Disconnect(client);
}
}
private void Channel_Faulted(object sender, EventArgs e)
{
(sender as ICommunicationObject).Abort();
}
现在的问题是:双工通道(回调通道)的状态是否会自动转换为客户端的状态,或者我必须像我一样处理故障状态?顺便说一句,我正在使用 NetTcpBinding。