private void FrmMain_Load(object sender, EventArgs e)
 {
     instanceContext       = new InstanceContext(this);
     hospitalServiceClient = new HospitalServiceClient(instanceContext);
     hospitalServiceClient.ClientCredentials.ClientCertificate = System.Net.CredentialCache.DefaultCredentials;
     try
     {
         hospitalServiceClient.Subscribe(clientId);
         txtID.Text = clientId;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         Environment.Exit(0);
     }
     System.Timers.Timer timer = new System.Timers.Timer(3000);
     timer.Elapsed +=
         (
             (object o, ElapsedEventArgs args) =>
     {
         try
         {
             if (hospitalServiceClient.State == CommunicationState.Faulted)
             {
                 hospitalServiceClient.Abort();
                 hospitalServiceClient = new HospitalServiceClient(instanceContext);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
         );
 }
 private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (hospitalServiceClient != null)
     {
         try
         {
             if (hospitalServiceClient.State != CommunicationState.Faulted)
             {
                 hospitalServiceClient.Unsubscribe(clientId);
                 hospitalServiceClient.Close();
             }
         }
         catch
         {
             hospitalServiceClient.Abort();
         }
     }
 }