Пример #1
0
        public TResult Call <TResult>(Func <TContract, TResult> call)
        {
            TResult result;

            try
            {
                if (ClientShell.State == CommunicationState.Closed || ClientShell.State == CommunicationState.Closing)
                {
                    ClientShell.Open();
                }

                result = call(ChannelProxy);
            }
            catch (Exception e)
            {
                var message = string.Format(
                    "While calling service method {0} on {1} an exception occurred", call.Method,
                    typeof(TContract).AssemblyQualifiedName);
                Logger.Log(LogLevel.Error, message as object, e);
                throw;
            }
            finally
            {
                Close();
            }
            return(result);
        }
Пример #2
0
        private void DisposeClientShell()
        {
            if (DisposingShell || _clientShell == null)
            {
                return;
            }

            DisposingShell = true;
            switch (_clientShell.State)
            {
            case CommunicationState.Faulted:
                _clientShell.Abort();
                break;

            default:
                try
                {
                    _clientShell.Close();
                }
                catch (Exception)
                {
                    _clientShell.Abort();
                }
                break;
            }
            if (_clientShell != null)
            {
                (_clientShell as IDisposable).Dispose();
            }
            _clientShell   = null;
            DisposingShell = false;
        }