/// <summary> /// Transitions proxy to closed state via Close() or Abort() /// dependently on current proxy state /// </summary> public static void CloseProxy <T>(this DuplexClientBase <T> proxy) where T : class { try { if (proxy.State != CommunicationState.Closed && proxy.State != CommunicationState.Faulted) { proxy.Close(); // may throw exception while closing } else { proxy.Abort(); } } catch (CommunicationException) { proxy.Abort(); throw; } }
private DuplexClientBase <T> InitiateClient(ref DuplexClientBase <T> client, bool skipSubscribe) { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "InitiateClient"); try { if (client == null || (client.State != System.ServiceModel.CommunicationState.Opened)) { if (this.ExecutorService.IsShutdown) { return(null); } if (client != null) { if (!skipSubscribe) { this.Unsubscribe(ref client); } try { if (client.State == CommunicationState.Opened) { client.Close(); } } catch { } client = null; } try { client = this.CreateClient(); } catch (Exception ex) { if (!this.SkipLogException) { Log.Exception(PROC, ex); } client = null; } if (client != null) { if (client is IWcfCallbackServiceClient) { ((IWcfCallbackServiceClient)client).SkipLogException = _skipLogException; } if (!skipSubscribe) { this.Subscribe(ref client); } } } } catch (Exception ex) { if (!this.SkipLogException) { Log.Exception(PROC, ex); } client = null; } return(client); }