在客户端,我处理代理状态,这样当它的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。
答案 0 :(得分:0)
Callback频道的状态通常会模仿客户端的状态,但无法保证。例如,如果客户端尝试访问服务器以关闭连接,则其状态可能为Closing
,而服务器端的状态可能为Opened
。假设每一方必须单独处理Closed
和Faulted
个状态,您正在正确处理它。
答案 1 :(得分:0)
我已经对我们应该使用什么样的绑定进行了一些研究,最后决定继续使用nettcp绑定。有关详细说明,请参阅我的博客
http://maheshde.blogspot.com.au/2013/06/duplex-communication-over-internet.html
我不知道为什么这些事件没有被解雇。但是每10分钟从客户端触发一次WCF调用我们的问题就解决了。