/// <summary>
        /// 构造
        /// </summary>
        /// <param name="address"></param>
        /// <param name="serverId"></param>
        public Server(Uri address, string serverId)
        {
            ServerId = serverId;
            _service = new ServiceHost(typeof(DuplexServerContract), address);
            _service.AddServiceEndpoint(typeof(IDuplexContract), new NetNamedPipeBinding(), address);

            //监听客户端初始化事件
            ServerMessageHandler.TryAddMessageListener(InnerMessageIds.CheckServerBinding, HasClientBoundServer);
            ServerMessageHandler.TryAddMessageListener(InnerMessageIds.CheckServerBinding, HasClientBoundServerAsync);
            ServerMessageHandler.TryAddMessageListener(InnerMessageIds.BindingServer, ClientBindingServer);
            ServerMessageHandler.TryAddMessageListener(InnerMessageIds.BindingServer, ClientBindingServerAsync);
            //在服务池中:注册此服务对应的消息处理
            DuplexServicePool.AddOrUpdateServiceHost(_service, ServerMessageHandler);
        }
Example #2
0
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="address"></param>
        /// <param name="clientId"></param>
        public Client(Uri address, string clientId)
        {
            ClientId = clientId;
            var callbackContract = new DuplexCallbackContract();

            _instanceContext = new InstanceContext(callbackContract);
            _endpointAddress = new EndpointAddress(address);
            _clientContract  = new DuplexClientContract(_instanceContext, new NetNamedPipeBinding(), _endpointAddress);

            //在服务池中:注册此客户端对应的消息处理
            DuplexServicePool.AddOrUpdateServiceHost(callbackContract, ClientMessageHandler);

            _checkBindingTimer.Elapsed += CheckBindingTimerOnElapsed;
        }