简体   繁体   English

NetTcpBinding中的双工通道状态会相应地自动转换为客户端的状态吗?

[英]Will Duplex Channel's State in NetTcpBinding automatically transition accordingly to client's?

On client side, I handle the proxy state so that when its State==CommunicationState.Faulted, it will automatically call Abort() and gracefully transition to CommunicationState.Closed. 在客户端,我处理代理状态,以便当其State == CommunicationState.Faulted时,它将自动调用Abort()并优雅地过渡到CommunicationState.Closed。 On server side, I have 2 events hooked up to callback channel 在服务器端,我有2个事件关联到回调通道

OperationContext.Current.Channel.Faulted += Channel_Faulted; OperationContext.Current.Channel.Closed += Channel_Closed;

Here are my events code 这是我的活动代码

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();
}

Now the question: Will the duplex channel's (the callback channel) state automatically transition accordingly to client's or I have to handle the Faulted State as I did? 现在的问题是:双工通道(回调通道)的状态是否会自动转换为客户端的状态,还是我必须像以前那样处理故障状态? I'm using NetTcpBinding by the way. 我正在使用NetTcpBinding。

The Callback channel's state will generally mimic the client's state, but this is not guaranteed . 回调通道的状态通常会模仿客户端的状态,但这不能保证 For example, if the client is trying to reach the server to close the connection, its state might be Closing while the state on the server side could be Opened . 例如,如果客户端尝试访问服务器以关闭连接,则其状态可能为正在Closing而服务器端的状态可能为Opened You are handling it correctly in assuming that each side must handle Closed and Faulted states individually. 您在假设每一侧都必须分别处理“ Closed和“ Faulted状态的情况下正确地进行了处理。

I have done bit research about what kind of binding should we use and finally decided to go ahead with nettcp binding. 我对应该使用哪种绑定进行了一些研究,最终决定继续进行nettcp绑定。 See my blog for detail explanation. 请参阅我的博客以获取详细说明。

http://maheshde.blogspot.com.au/2013/06/duplex-communication-over-internet.html http://maheshde.blogspot.com.au/2013/06/duplex-communication-over-internet.html

I have no idea why those events not fired. 我不知道为什么这些事件没有被解雇。 But triggering WCF call from client every 10 minutes our problem solved. 但是每隔10分钟触发一次来自客户端的WCF呼叫,我们的问题就解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM