Esempio n. 1
0
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            if (error is FaultException)
            {
                return;
            }

            if (this.channelDisp.Listener.State != CommunicationState.Opened)
            {
                var faultCodeToUse = WcfRemoteExceptionInformation.FaultCodeRetry;
                var faultReason    = new FaultReason(WcfRemoteExceptionInformation.ToString(error));
                var faultException = new FaultException(faultReason, faultCodeToUse);
                var mssgFault      = faultException.CreateMessageFault();
                fault = Message.CreateMessage(version, mssgFault, null);
            }
        }
        /// <summary>
        /// Method that examines the exception and determines how that exception can be handled.
        /// </summary>
        /// <param name="exceptionInformation">Information about the exception</param>
        /// <param name="retrySettings">The operation retry preferences.</param>
        /// <param name="result">Result of the exception handling</param>
        /// <returns>true if the exception is handled, false otherwise</returns>
        bool IExceptionHandler.TryHandleException(
            ExceptionInformation exceptionInformation,
            OperationRetrySettings retrySettings,
            out ExceptionHandlingResult result)
        {
            var e = exceptionInformation.Exception;

            // retry with resolve - these exceptions indicate a possible fail over
            if ((e is EndpointNotFoundException) ||
                (e is CommunicationObjectAbortedException) ||
                (e is CommunicationObjectFaultedException) ||
                (e is ObjectDisposedException) ||
                (e is ChannelTerminatedException))
            {
                result = new ExceptionHandlingRetryResult(
                    e,
                    false,
                    retrySettings,
                    int.MaxValue);
                return(true);
            }


            // retry on timeout and service busy exceptions
            if ((e is TimeoutException) ||
                (e is ServerTooBusyException))
            {
                result = new ExceptionHandlingRetryResult(
                    e,
                    true,
                    retrySettings,
                    int.MaxValue);
                return(true);
            }


            // Derived types of Communication Exception that are not retriable.
            if ((e is ActionNotSupportedException) ||
                (e is AddressAccessDeniedException))
            {
                result = new ExceptionHandlingThrowResult()
                {
                    ExceptionToThrow = e
                };
                return(true);
            }

            // Security related derived types of Communication Exception that are not retriable
            if (e is SecurityAccessDeniedException)
            {
                result = new ExceptionHandlingThrowResult()
                {
                    ExceptionToThrow = e
                };
                return(true);
            }


            var faultException = e as FaultException;

            if (faultException != null)
            {
                if (faultException.Code.Name == WcfRemoteExceptionInformation.FaultCodeName)
                {
                    var actualException = WcfRemoteExceptionInformation.ToException(faultException.Reason.ToString());

                    if (faultException.Code.SubCode.Name == WcfRemoteExceptionInformation.FaultSubCodeRetryName)
                    {
                        result = new ExceptionHandlingRetryResult(
                            actualException,
                            false,
                            retrySettings,
                            int.MaxValue);
                        return(true);
                    }
                }
            }

            // retry on all communication exceptions, including the protocol exceptions for default max retry
            if ((faultException == null) && (e is CommunicationException))
            {
                result = new ExceptionHandlingRetryResult(
                    e,
                    false,
                    retrySettings,
                    retrySettings.DefaultMaxRetryCount);
                return(true);
            }

            result = null;
            return(false);
        }