_channel.StopListening(null);// 3/2 停止监听 ChannelServices.UnregisterChannel(_channel);// 4/2 注销通道

 

        private void Server_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_channel != null)
            {
                _channel.StopListening(null);// 3/2 停止监听
                ChannelServices.UnregisterChannel(_channel);// 4/2 解除注册
            }
            //
            //
            //3)注销通道
            //如果要关闭 Remoting 的服务,则需要注销通道,也可以关闭对通道的监听。在Remoting
            //中当我们注册通道的时候,就自动开启了通道的监听。而如果关闭了对通道的监听,则该通
            //道就无法接受客户端的请求,但通道仍然存在,如果你想再一次注册该通道,会抛出异常。
            ////获得当前已注册的通道;
            //IChannel[] channels = ChannelServices.RegisteredChannels;
            ////关闭指定名为MyTcp 的通道;
            //foreach (IChannel eachChannel in channels)
            //{
            //if (eachChannel.ChannelName == "MyTcp")
            //{
            //TcpChannel tcpChannel = (TcpChannel)eachChannel;
            ////关闭监听;
            //tcpChannel.StopListening(null);
            ////注销通道;
            //ChannelServices.UnregisterChannel(tcpChannel);
            //}
            //}
            //代码中,RegisterdChannel 属性获得的是当前已注册的通道。在Remoting 中,是允许同
            //时注册多个通道的,这一点会在后面说明。
            //
            //
        }

 

posted @ 2018-02-12 15:35  sky20080101  阅读(192)  评论(0)    收藏  举报