void StartExchange()
 {
     if (_isStarting)
     {
         return;
     }
     _isStarting = true;
     try
     {
         _logger.Info("开始启动Exchange服务");
         if (string.IsNullOrEmpty(_posApiDomain))
         {
             _logger.Error("未配置PosApiDomain,启动SyncData服务失败。");
             return;
         }
         if (string.IsNullOrEmpty(ClientId))
         {
             throw new Exception("未配置ClientId,启动Exchange服务失败。");
         }
         _logger.InfoFormat("PosApiDomain:[{0}]", _posApiDomain);
         _client = new Proxy.MessageServiceClient(new System.ServiceModel.InstanceContext(this));
         _client.Subscribe(ClientId);
         var commObj = _client as ICommunicationObject;
         commObj.Faulted += Client_Faulted;
         commObj.Closing += Client_Closing;
         commObj.Closed  += Client_Closed;
         _logger.Info("启动Exchange服务 成功");
         _pingTimer.Change(_pingDueTime, Timeout.Infinite);
         //启动成功,重试数据重置。
         _retryCount   = 0;
         _retryDueTime = 5000;
     }
     catch (Exception ex)
     {
         _logger.Error("启动Exchange服务 失败, 出现异常", ex);
         _retryCount++;
     }
     finally
     {
         _isStarting = false;
     }
 }
 private void btnOperate_Click(object sender, EventArgs e)
 {
     if (_isRunning)
     {
         _client.Unsubscribe(_clientId);
         _client.Close();
     }
     else
     {
         if (string.IsNullOrEmpty(txtClientId.Text))
         {
             MessageBox.Show("请填写ClientId");
             return;
         }
         _clientId = txtClientId.Text;
         _client   = new Proxy.MessageServiceClient(new System.ServiceModel.InstanceContext(this));
         _client.Subscribe(_clientId);
     }
     _isRunning = !_isRunning;
     RefreshStatus();
 }