예제 #1
0
        /// <summary>
        /// 关闭通道连接并释放资源
        /// </summary>
        /// <example>WcfClientProxy.CloseAndDispose((IClientChannel)_IService);</example>
        /// <param name="serviceProxy">代理实例</param>
        public static void CloseAndDispose(IClientChannel serviceProxy)
        {
            if (serviceProxy == null)
            {
                return;
            }

            try
            {
                if (serviceProxy.State == CommunicationState.Opened)
                {
                    serviceProxy.Close();
                }
                serviceProxy.Dispose();
            }
            catch (CommunicationException) { serviceProxy.Abort(); }
            catch (TimeoutException) { serviceProxy.Abort(); }
            catch (Exception)
            {
                serviceProxy.Abort();
                //throw;
                ///todo:未知异常,暂不抛出,考虑记录日志
            }
            finally
            {
                serviceProxy = null;
            }
        }
예제 #2
0
        private void FreeAllResources()
        {
            if (!_isDisposed)
            {
                _isDisposeRequested = true;
                _isDisposed = true;

                var prevState = ChangeStateSafe(StableConnectionState.Invalid);
                Contract.Assume(prevState == StableConnectionState.Closed);

                if (_concurrencyTrackSemaphore != null)
                    _concurrencyTrackSemaphore.Dispose();

                try
                {
                    if (_channel.State == CommunicationState.Faulted)
                        _channel.Abort();
                    _channel.Dispose();
                }
                catch (Exception ex)
                {
                    Logger.Logger.Instance.Debug(ex, "WCF channel close exception.");
                }
            }
        }
        protected override void OnClose()
        {
            base.OnClose();
            IClientChannel channel = _LoggingService as IClientChannel;

            if (channel != null)
            {
                channel.Dispose();
            }
        }
예제 #4
0
 public static void CloseClientChannel(IClientChannel c)
 {
     try {
         c.Close();
     } catch {
         c.Abort();
     } finally {
         c.Dispose();
     }
 }
예제 #5
0
        /// <summary>
        /// Closes the connection channel.
        /// </summary>
        public void CloseConnectionChannel()
        {
            if (_proxy != null)
            {
                IClientChannel channel = _proxy as IClientChannel;

                if (channel.State == CommunicationState.Faulted)
                {
                    channel.Abort();
                    channel.Dispose();
                }
                else
                {
                    channel.Close();
                    channel.Dispose();
                }

                _proxy = null;
            }
        }
예제 #6
0
 /// <summary>
 /// Close connection to service and dispose of it
 /// </summary>
 /// <param name="serviceProxy">Hydrated proxy</param>
 public static void CloseAndDispose(IClientChannel serviceProxy)
 {
     if (serviceProxy == null)
     {
         return;
     }
     if (serviceProxy.State == CommunicationState.Opened)
     {
         serviceProxy.Close();
     }
     serviceProxy.Dispose();
 }
예제 #7
0
        /// <summary>
        /// Frees managed resources.
        /// </summary>
        public void Dispose()
        {
            if (RemotingClient.DefaultRemotingClient == this)
            {
                RemotingClient.DefaultRemotingClient = null;
            }

            _clientInstances.TryRemove(_config.UniqueClientInstanceName, out _);

            Disconnect();

            _cancellationTokenSource.Cancel();
            _delegateRegistry.Clear();

            if (_rawMessageTransport != null)
            {
                _rawMessageTransport.ReceiveMessage -= OnMessage;
                _rawMessageTransport = null;
            }

            if (_channel != null)
            {
                _channel.Dispose();
                _channel = null;
            }

            if (_handshakeCompletedWaitHandle != null)
            {
                _handshakeCompletedWaitHandle.Dispose();
                _handshakeCompletedWaitHandle = null;
            }

            if (_authenticationCompletedWaitHandle != null)
            {
                _authenticationCompletedWaitHandle.Dispose();
                _authenticationCompletedWaitHandle = null;
            }

            if (_goodbyeCompletedWaitHandle != null)
            {
                _goodbyeCompletedWaitHandle.Dispose();
                _goodbyeCompletedWaitHandle = null;
            }

            _keyPair?.Dispose();
        }
예제 #8
0
        static void Main(string[] args)
        {
            var basicHttpBinding = new BasicHttpBinding();
            var endpont          = new EndpointAddress("http://localhost:8080/RoutingService/RoutingService.StoredConnectionStringsService.svc");

            var connectionStringService = new ChannelFactory <IConnectionStringService>(basicHttpBinding, endpont);

            IConnectionStringService client = connectionStringService.CreateChannel();

            ConnectionString connectionString = client.GetConnectionString("RoutingService", "abcd1234", "DefaultConnectionString");

            IClientChannel chanel = (IClientChannel)client;

            chanel.Close();
            chanel.Dispose();

            Console.WriteLine(connectionString);
            Console.ReadKey();
        }
        private bool ConfirmChannelAcceptable()
        {
            bool ret = true;

            if (_LoggingService == null)
            {
                ret = CreateChannel();
            }
            else
            {
                IClientChannel channel = _LoggingService as IClientChannel;
                if (channel != null && (channel.State == CommunicationState.Faulted || channel.State == CommunicationState.Closed))
                {
                    LogLog.Debug(typeDescriptor, "Channel not in a good state, disposing and creating a new one");
                    channel.Dispose();
                    return(CreateChannel());
                }
            }
            return(ret);
        }
예제 #10
0
        public void Dispose()
        {
            if (serverChannel != null)
            {
                serverChannel.Dispose();
                serverChannel = null;
            }

            if (callbackChannel != null)
            {
                callbackChannel.Dispose();
                callbackChannel = null;
            }

            if (assemblyLoader != null)
            {
                assemblyLoader.Dispose();
                assemblyLoader = null;
            }
        }
예제 #11
0
        /// <summary>
        /// Closes a client channel
        /// </summary>
        /// <param name="clientChannel"></param>
        public static void CloseClientChannel(IClientChannel clientChannel)
        {
            if (clientChannel == null)
            {
                return;
            }

            try
            {
                clientChannel.Close();
            }
            catch (Exception)
            {
                clientChannel.Abort();
            }
            finally
            {
                clientChannel.Dispose();
            }
        }
예제 #12
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(Boolean disposing)
        {
            if (disposing)
            {
                if (mService != null)
                {
                    IClientChannel clientChannel = mService as IClientChannel;

                    if (clientChannel.State == CommunicationState.Faulted)
                    {
                        clientChannel.Abort();
                    }
                    else
                    {
                        clientChannel.Close();
                    }

                    clientChannel.Dispose();
                }
            }
        }
예제 #13
0
 public void Dispose()
 {
     _clientChannel.Dispose();
 }