void ProvideFaultOfLastResort(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (faultInfo.Fault == null)
     {
         FaultCode code = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);
         code = FaultCode.CreateReceiverFaultCode(code);
         string action = FaultCodeConstants.Actions.NetDispatcher;
         MessageFault fault;
         if (this.debug)
         {
             faultInfo.DefaultFaultAction = action;
             fault = MessageFault.CreateFault(code, new FaultReason(error.Message), new ExceptionDetail(error));
         }
         else
         {
             string reason = this.isOnServer ? SR.GetString(SR.SFxInternalServerError) : SR.GetString(SR.SFxInternalCallbackError);
             fault = MessageFault.CreateFault(code, new FaultReason(reason));
         }
         faultInfo.IsConsideredUnhandled = true;
         faultInfo.Fault = Message.CreateMessage(this.messageVersion, fault, action);
     }
     //if this is an InternalServiceFault coming from another service dispatcher we should treat it as unhandled so that the channels are cleaned up
     else if (error != null)
     {
         FaultException e = error as FaultException;
         if (e != null && e.Fault != null && e.Fault.Code != null && e.Fault.Code.SubCode != null &&
             string.Compare(e.Fault.Code.SubCode.Namespace, FaultCodeConstants.Namespaces.NetDispatch, StringComparison.Ordinal) == 0 &&
             string.Compare(e.Fault.Code.SubCode.Name, FaultCodeConstants.Codes.InternalServiceFault, StringComparison.Ordinal) == 0)
         {
             faultInfo.IsConsideredUnhandled = true;
         }
     }
 }
Example #2
0
 internal void ProvideFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
 {
     ProvideWellKnownFault(e, faultConverter, ref faultInfo);
     for (int i = 0; i < _handlers.Length; i++)
     {
         Message m = faultInfo.Fault;
         _handlers[i].ProvideFault(e, _messageVersion, ref m);
         faultInfo.Fault = m;
         if (TD.FaultProviderInvokedIsEnabled())
         {
             TD.FaultProviderInvoked(_handlers[i].GetType().FullName, e.Message);
         }
     }
     this.ProvideFaultOfLastResort(e, ref faultInfo);
 }
Example #3
0
 private void ProvideWellKnownFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
 {
     Message faultMessage;
     if (faultConverter != null && faultConverter.TryCreateFaultMessage(e, out faultMessage))
     {
         faultInfo.Fault = faultMessage;
         return;
     }
     else if (e is NetDispatcherFaultException)
     {
         NetDispatcherFaultException ndfe = e as NetDispatcherFaultException;
         if (_debug)
         {
             ExceptionDetail detail = new ExceptionDetail(ndfe);
             faultInfo.Fault = Message.CreateMessage(_messageVersion, MessageFault.CreateFault(ndfe.Code, ndfe.Reason, detail), ndfe.Action);
         }
         else
         {
             faultInfo.Fault = Message.CreateMessage(_messageVersion, ndfe.CreateMessageFault(), ndfe.Action);
         }
     }
 }
 private bool HandleErrorCommon(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     bool flag;
     if ((faultInfo.Fault != null) && !faultInfo.IsConsideredUnhandled)
     {
         flag = true;
     }
     else
     {
         flag = false;
     }
     try
     {
         if (TD.ServiceExceptionIsEnabled())
         {
             TD.ServiceException(error.ToString(), error.GetType().FullName);
         }
         for (int i = 0; i < this.handlers.Length; i++)
         {
             bool handled = this.handlers[i].HandleError(error);
             flag = handled || flag;
             if (TD.ErrorHandlerInvokedIsEnabled())
             {
                 TD.ErrorHandlerInvoked(this.handlers[i].GetType().FullName, handled, error.GetType().FullName);
             }
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(exception);
     }
     return flag;
 }
 private void ProvideWellKnownFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
 {
     Message message;
     if ((faultConverter != null) && faultConverter.TryCreateFaultMessage(e, out message))
     {
         faultInfo.Fault = message;
     }
     else if (e is NetDispatcherFaultException)
     {
         NetDispatcherFaultException exception = e as NetDispatcherFaultException;
         if (this.debug)
         {
             ExceptionDetail detail = new ExceptionDetail(exception);
             faultInfo.Fault = Message.CreateMessage(this.messageVersion, MessageFault.CreateFault(exception.Code, exception.Reason, detail), exception.Action);
         }
         else
         {
             faultInfo.Fault = Message.CreateMessage(this.messageVersion, exception.CreateMessageFault(), exception.Action);
         }
     }
 }
 private void ProvideFaultAndReplyFailure(RequestContext request, Exception exception, ref ErrorHandlerFaultInfo faultInfo, out bool replied)
 {
     replied = false;
     bool isFault = false;
     try
     {
         isFault = request.RequestMessage.IsFault;
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
     }
     bool enableFaults = false;
     if (this.listener != null)
     {
         enableFaults = this.listener.ChannelDispatcher.EnableFaults;
     }
     else if ((this.channel != null) && this.channel.IsClient)
     {
         enableFaults = this.channel.ClientRuntime.EnableFaults;
     }
     if (!isFault && enableFaults)
     {
         this.ProvideFault(exception, ref faultInfo);
         if (faultInfo.Fault != null)
         {
             Message fault = faultInfo.Fault;
             replied = this.TryReply(request, fault);
             try
             {
                 fault.Close();
             }
             catch (Exception exception3)
             {
                 if (Fx.IsFatal(exception3))
                 {
                     throw;
                 }
                 this.HandleError(exception3);
             }
         }
     }
 }
 internal bool HandleError(Exception e)
 {
     ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo();
     return this.HandleError(e, ref faultInfo);
 }
 bool HandleError(Exception e, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (e == null)
     {
         Fx.Assert(SR.GetString(SR.GetString(SR.SFxNonExceptionThrown)));
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.GetString(SR.SFxNonExceptionThrown))));
     }
     if (this.listener != null)
     {
         return listener.ChannelDispatcher.HandleError(e, ref faultInfo);
     }
     else if (this.channel != null)
     {
         return this.channel.ClientRuntime.CallbackDispatchRuntime.ChannelDispatcher.HandleError(e, ref faultInfo);
     }
     else
     {
         return false;
     }
 }
        bool HandleErrorContinuation(Exception e, RequestContext request, ServiceChannel channel, ref ErrorHandlerFaultInfo faultInfo, bool replied)
        {
            if (replied)
            {
                try
                {
                    request.Close();
                }
                catch (Exception e1)
                {
                    if (Fx.IsFatal(e1))
                    {
                        throw;
                    }
                    this.HandleError(e1);
                }
            }
            else
            {
                request.Abort();
            }
            if (!this.HandleError(e, ref faultInfo) && this.hasSession)
            {
                if (channel != null)
                {
                    if (replied)
                    {
                        TimeoutHelper timeoutHelper = new TimeoutHelper(CloseAfterFaultTimeout);
                        try
                        {
                            channel.Close(timeoutHelper.RemainingTime());
                        }
                        catch (Exception e2)
                        {
                            if (Fx.IsFatal(e2))
                            {
                                throw;
                            }
                            this.HandleError(e2);
                        }
                        try
                        {
                            this.binder.CloseAfterFault(timeoutHelper.RemainingTime());
                        }
                        catch (Exception e3)
                        {
                            if (Fx.IsFatal(e3))
                            {
                                throw;
                            }
                            this.HandleError(e3);
                        }
                    }
                    else
                    {
                        channel.Abort();
                        this.binder.Abort();
                    }
                }
                else
                {
                    if (replied)
                    {
                        try
                        {
                            this.binder.CloseAfterFault(CloseAfterFaultTimeout);
                        }
                        catch (Exception e4)
                        {
                            if (Fx.IsFatal(e4))
                            {
                                throw;
                            }
                            this.HandleError(e4);
                        }
                    }
                    else
                    {
                        this.binder.Abort();
                    }
                }
            }

            return true;
        }
Example #10
0
        private bool HandleErrorContinuation(Exception e, RequestContext request, ServiceChannel channel, ref ErrorHandlerFaultInfo faultInfo, bool replied)
        {
            if (replied)
            {
                try
                {
                    request.Close();
                }
                catch (Exception e1)
                {
                    if (Fx.IsFatal(e1))
                    {
                        throw;
                    }
                    this.HandleError(e1);
                }
            }
            else
            {
                request.Abort();
            }
            if (!this.HandleError(e, ref faultInfo) && _hasSession)
            {
                if (channel != null)
                {
                    if (replied)
                    {
                        TimeoutHelper timeoutHelper = new TimeoutHelper(CloseAfterFaultTimeout);
                        try
                        {
                            channel.Close(timeoutHelper.RemainingTime());
                        }
                        catch (Exception e2)
                        {
                            if (Fx.IsFatal(e2))
                            {
                                throw;
                            }
                            this.HandleError(e2);
                        }
                        try
                        {
                            _binder.CloseAfterFault(timeoutHelper.RemainingTime());
                        }
                        catch (Exception e3)
                        {
                            if (Fx.IsFatal(e3))
                            {
                                throw;
                            }
                            this.HandleError(e3);
                        }
                    }
                    else
                    {
                        channel.Abort();
                        _binder.Abort();
                    }
                }
                else
                {
                    if (replied)
                    {
                        try
                        {
                            _binder.CloseAfterFault(CloseAfterFaultTimeout);
                        }
                        catch (Exception e4)
                        {
                            if (Fx.IsFatal(e4))
                            {
                                throw;
                            }
                            this.HandleError(e4);
                        }
                    }
                    else
                    {
                        _binder.Abort();
                    }
                }
            }

            return(true);
        }
 void ProvideFault(Exception e, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (this.listener != null)
     {
         this.listener.ChannelDispatcher.ProvideFault(e, this.requestInfo.Channel == null ? this.binder.Channel.GetProperty<FaultConverter>() : this.requestInfo.Channel.GetProperty<FaultConverter>(), ref faultInfo);
     }
     else if (this.channel != null)
     {
         DispatchRuntime dispatchBehavior = this.channel.ClientRuntime.CallbackDispatchRuntime;
         dispatchBehavior.ChannelDispatcher.ProvideFault(e, this.channel.GetProperty<FaultConverter>(), ref faultInfo);
     }
 }
Example #12
0
        internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation,
                            ServiceChannel channel, ChannelHandler channelHandler, bool cleanThread,
                            OperationContext operationContext, InstanceContext instanceContext, EventTraceActivity eventTraceActivity)
        {
            Fx.Assert((operationContext != null), "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), operationContext == null");
            Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler == null");

            this.Activity           = null;
            this.EventTraceActivity = eventTraceActivity;
            this.AsyncResult        = null;
            this.CanSendReply       = true;
            this.Channel            = channel;
            this.channelHandler     = channelHandler;
            this.Correlation        = EmptyArray <object> .Allocate(operation.Parent.CorrelationCount);

            this.DidDeserializeRequestBody = false;
            this.Error              = null;
            this.ErrorProcessor     = null;
            this.FaultInfo          = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction);
            this.HasSecurityContext = false;
            this.Instance           = null;
            this.MessageRpcOwnsInstanceContextThrottle = false;
            this.NextProcessor        = null;
            this.NotUnderstoodHeaders = null;
            this.Operation            = operation;
            this.OperationContext     = operationContext;
            _paused = false;
            this.ParametersDisposed         = false;
            this.Request                    = request;
            this.RequestContext             = requestContext;
            this.RequestContextThrewOnReply = false;
            this.SuccessfullySendReply      = false;
            this.RequestVersion             = request.Version;
            this.Reply = null;
            this.ReplyTimeoutHelper              = new TimeoutHelper();
            this.SecurityContext                 = null;
            this.InstanceContext                 = instanceContext;
            this.SuccessfullyBoundInstance       = false;
            this.SuccessfullyIncrementedActivity = false;
            this.SuccessfullyLockedInstance      = false;
            _switchedThreads            = !cleanThread;
            this.InputParameters        = null;
            this.OutputParameters       = null;
            this.ReturnParameter        = null;
            _isInstanceContextSingleton = false;
            _invokeContinueGate         = null;

            if (!operation.IsOneWay && !operation.Parent.ManualAddressing)
            {
                this.RequestID   = request.Headers.MessageId;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request);
            }
            else
            {
                this.RequestID   = null;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo();
            }

            if (DiagnosticUtility.ShouldUseActivity)
            {
                this.Activity = TraceUtility.ExtractActivity(this.Request);
            }

            if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity)
            {
                this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request);
            }
            else
            {
                this.ResponseActivityId = Guid.Empty;
            }

            this.InvokeNotification = new MessageRpcInvokeNotification(this.Activity, this.channelHandler);

            if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                if (this.Request != null)
                {
                    this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true);
                }
            }
        }
Example #13
0
        internal bool HandleError(Exception e)
        {
            ErrorHandlerFaultInfo dummy = new ErrorHandlerFaultInfo();

            return(this.HandleError(e, ref dummy));
        }
Example #14
0
 internal bool HandleError(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     return(HandleErrorCommon(error, ref faultInfo));
 }
Example #15
0
        internal bool HandleError(Exception error)
        {
            ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction);

            return(HandleError(error, ref faultInfo));
        }
 private void ReplyFailure(RequestContext request, Message fault, string action, string reason, FaultCode code)
 {
     bool flag;
     FaultException e = new FaultException(reason, code);
     System.ServiceModel.Dispatcher.ErrorBehavior.ThrowAndCatch(e);
     ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(action) {
         Fault = fault
     };
     this.ProvideFaultAndReplyFailure(request, e, ref faultInfo, out flag);
     this.HandleError(e, ref faultInfo);
 }
 void ReplyFailure(RequestContext request, Message fault, string action, string reason, FaultCode code)
 {
     FaultException exception = new FaultException(reason, code);
     ErrorBehavior.ThrowAndCatch(exception);
     ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(action);
     faultInfo.Fault = fault;
     bool replied, replySentAsync;
     ProvideFaultAndReplyFailure(request, exception, ref faultInfo, out replied, out replySentAsync);
     this.HandleError(exception, ref faultInfo);
 }
Example #18
0
        private void ProvideFaultAndReplyFailure(RequestContext request, Exception exception, ref ErrorHandlerFaultInfo faultInfo, out bool replied, out bool replySentAsync)
        {
            replied        = false;
            replySentAsync = false;
            bool requestMessageIsFault = false;

            try
            {
                requestMessageIsFault = request.RequestMessage.IsFault;
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                // do not propagate non-fatal exceptions
            }

            bool enableFaults = false;
            if (_listener != null)
            {
                enableFaults = _listener.ChannelDispatcher.EnableFaults;
            }
            else if (_channel != null && _channel.IsClient)
            {
                enableFaults = _channel.ClientRuntime.EnableFaults;
            }

            if ((!requestMessageIsFault) && enableFaults)
            {
                this.ProvideFault(exception, ref faultInfo);
                if (faultInfo.Fault != null)
                {
                    Message reply = faultInfo.Fault;
                    try
                    {
                        try
                        {
                            if (this.PrepareReply(request, reply))
                            {
                                if (_sendAsynchronously)
                                {
                                    var state = new ContinuationState {
                                        ChannelHandler = this, Channel = _channel, Exception = exception, FaultInfo = faultInfo, Request = request, Reply = reply
                                    };
                                    var result = request.BeginReply(reply, ChannelHandler.s_onAsyncReplyComplete, state);
                                    if (result.CompletedSynchronously)
                                    {
                                        ChannelHandler.AsyncReplyComplete(result, state);
                                        replied = true;
                                    }
                                    else
                                    {
                                        replySentAsync = true;
                                    }
                                }
                                else
                                {
                                    request.Reply(reply);
                                    replied = true;
                                }
                            }
                        }
                        finally
                        {
                            if (!replySentAsync)
                            {
                                reply.Close();
                            }
                        }
                    }
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }
                        this.HandleError(e);
                    }
                }
            }
        }
        void ProvideFaultAndReplyFailure(RequestContext request, Exception exception, ref ErrorHandlerFaultInfo faultInfo, out bool replied, out bool replySentAsync)
        {
            replied = false;
            replySentAsync = false;
            bool requestMessageIsFault = false;
            try
            {
                requestMessageIsFault = request.RequestMessage.IsFault;
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                // ---- it
            }

            bool enableFaults = false;
            if (this.listener != null)
            {
                enableFaults = this.listener.ChannelDispatcher.EnableFaults;
            }
            else if (this.channel != null && this.channel.IsClient)
            {
                enableFaults = this.channel.ClientRuntime.EnableFaults;
            }

            if ((!requestMessageIsFault) && enableFaults)
            {
                this.ProvideFault(exception, ref faultInfo);
                if (faultInfo.Fault != null)
                {
                    Message reply = faultInfo.Fault;
                    try
                    {
                        try
                        {
                            if (this.PrepareReply(request, reply))
                            {
                                if (this.sendAsynchronously)
                                {
                                    var state = new ContinuationState { ChannelHandler = this, Channel = channel, Exception = exception, FaultInfo = faultInfo, Request = request, Reply = reply };
                                    var result = request.BeginReply(reply, ChannelHandler.onAsyncReplyComplete, state);
                                    if (result.CompletedSynchronously)
                                    {
                                        ChannelHandler.AsyncReplyComplete(result, state);
                                        replied = true;
                                    }
                                    else
                                    {
                                        replySentAsync = true;
                                    }
                                }
                                else
                                {
                                    request.Reply(reply);
                                    replied = true;
                                }
                            }
                        }
                        finally
                        {
                            if (!replySentAsync)
                            {
                                reply.Close();
                            }
                        }
                    }
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }
                        this.HandleError(e);
                    }
                }
            }
        }
 private bool HandleError(Exception e, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (e == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString(System.ServiceModel.SR.GetString("SFxNonExceptionThrown"))));
     }
     if (this.listener != null)
     {
         return this.listener.ChannelDispatcher.HandleError(e, ref faultInfo);
     }
     return ((this.channel != null) && this.channel.ClientRuntime.CallbackDispatchRuntime.ChannelDispatcher.HandleError(e, ref faultInfo));
 }
 internal bool HandleError(Exception e)
 {
     ErrorHandlerFaultInfo dummy = new ErrorHandlerFaultInfo();
     return this.HandleError(e, ref dummy);
 }
        bool HandleErrorCommon(Exception error, ref ErrorHandlerFaultInfo faultInfo)
        {
            bool handled;
            if (faultInfo.Fault != null   // there is a message
                && !faultInfo.IsConsideredUnhandled) // and it's not the internal-server-error one
            {
                handled = true;
            }
            else
            {
                handled = false;
            }

            try
            {
                if (TD.ServiceExceptionIsEnabled())
                {
                    TD.ServiceException(null, error.ToString(), error.GetType().FullName);
                }
                for (int i = 0; i < this.handlers.Length; i++)
                {
                    bool handledByThis = handlers[i].HandleError(error);
                    handled = handledByThis || handled;
                    if (TD.ErrorHandlerInvokedIsEnabled())
                    {
                        TD.ErrorHandlerInvoked(handlers[i].GetType().FullName, handledByThis, error.GetType().FullName);
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
            }
            return handled;
        }
        bool HandleError(Exception e, RequestContext request, ServiceChannel channel)
        {
            ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction);
            bool replied, replySentAsync;
            ProvideFaultAndReplyFailure(request, e, ref faultInfo, out replied, out replySentAsync);

            if (!replySentAsync)
            {
                return this.HandleErrorContinuation(e, request, channel, ref faultInfo, replied);
            }
            else
            {
                return false;
            }
        }
 internal bool HandleError(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     return HandleErrorCommon(error, ref faultInfo);
 }
        internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation,
            ServiceChannel channel, ServiceHostBase host, ChannelHandler channelHandler, bool cleanThread,
            OperationContext operationContext, InstanceContext instanceContext, EventTraceActivity eventTraceActivity)
        {
            Fx.Assert((operationContext != null), "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), operationContext == null");
            Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler == null");

            this.Activity = null;
            this.EventTraceActivity = eventTraceActivity;            
            this.AsyncResult = null;
            this.CanSendReply = true;
            this.Channel = channel;
            this.channelHandler = channelHandler;
            this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount);
            this.CorrelationCallback = null;
            this.DidDeserializeRequestBody = false;
            this.TransactionMessageProperty = null;
            this.TransactedBatchContext = null;
            this.Error = null;
            this.ErrorProcessor = null;
            this.FaultInfo = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction);
            this.HasSecurityContext = false;
            this.Host = host;
            this.Instance = null;
            this.MessageRpcOwnsInstanceContextThrottle = false;
            this.NextProcessor = null;
            this.NotUnderstoodHeaders = null;
            this.Operation = operation;
            this.OperationContext = operationContext;
            this.paused = false;
            this.ParametersDisposed = false;
            this.ReceiveContext = null;
            this.Request = request;
            this.RequestContext = requestContext;
            this.RequestContextThrewOnReply = false;
            this.SuccessfullySendReply = false;
            this.RequestVersion = request.Version;
            this.Reply = null;
            this.ReplyTimeoutHelper = new TimeoutHelper();
            this.SecurityContext = null;
            this.InstanceContext = instanceContext;
            this.SuccessfullyBoundInstance = false;
            this.SuccessfullyIncrementedActivity = false;
            this.SuccessfullyLockedInstance = false;
            this.switchedThreads = !cleanThread;
            this.transaction = null;
            this.InputParameters = null;
            this.OutputParameters = null;
            this.ReturnParameter = null;
            this.isInstanceContextSingleton = InstanceContextProviderBase.IsProviderSingleton(this.Channel.DispatchRuntime.InstanceContextProvider);
            this.invokeContinueGate = null;

            if (!operation.IsOneWay && !operation.Parent.ManualAddressing)
            {
                this.RequestID = request.Headers.MessageId;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request);
            }
            else
            {
                this.RequestID = null;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo();
            }

            this.HostingProperty = AspNetEnvironment.Current.GetHostingProperty(request, true);

            if (DiagnosticUtility.ShouldUseActivity)
            {
                this.Activity = TraceUtility.ExtractActivity(this.Request);
            }

            if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity)
            {
                this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request);
            }
            else
            {
                this.ResponseActivityId = Guid.Empty;
            }

            this.InvokeNotification = new MessageRpcInvokeNotification(this.Activity, this.channelHandler);

            if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                if (this.Request != null)
                {
                    this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true);
                }
            }
        }
 private bool HandleError(Exception e, RequestContext request, ServiceChannel channel)
 {
     bool flag;
     ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction);
     this.ProvideFaultAndReplyFailure(request, e, ref faultInfo, out flag);
     if (flag)
     {
         try
         {
             request.Close();
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             this.HandleError(exception);
         }
     }
     else
     {
         request.Abort();
     }
     if (!this.HandleError(e, ref faultInfo) && this.hasSession)
     {
         if (channel != null)
         {
             if (flag)
             {
                 TimeoutHelper helper = new TimeoutHelper(CloseAfterFaultTimeout);
                 try
                 {
                     channel.Close(helper.RemainingTime());
                 }
                 catch (Exception exception2)
                 {
                     if (Fx.IsFatal(exception2))
                     {
                         throw;
                     }
                     this.HandleError(exception2);
                 }
                 try
                 {
                     this.binder.CloseAfterFault(helper.RemainingTime());
                     goto Label_0117;
                 }
                 catch (Exception exception3)
                 {
                     if (Fx.IsFatal(exception3))
                     {
                         throw;
                     }
                     this.HandleError(exception3);
                     goto Label_0117;
                 }
             }
             channel.Abort();
             this.binder.Abort();
         }
         else
         {
             if (flag)
             {
                 try
                 {
                     this.binder.CloseAfterFault(CloseAfterFaultTimeout);
                     goto Label_0117;
                 }
                 catch (Exception exception4)
                 {
                     if (Fx.IsFatal(exception4))
                     {
                         throw;
                     }
                     this.HandleError(exception4);
                     goto Label_0117;
                 }
             }
             this.binder.Abort();
         }
     }
 Label_0117:
     return true;
 }
 internal bool HandleError(Exception error)
 {
     ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction);
     return HandleError(error, ref faultInfo);
 }
Example #28
0
        private void ProvideWellKnownFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
        {
            Message faultMessage;

            if (faultConverter != null && faultConverter.TryCreateFaultMessage(e, out faultMessage))
            {
                faultInfo.Fault = faultMessage;
                return;
            }
            else if (e is NetDispatcherFaultException)
            {
                NetDispatcherFaultException ndfe = e as NetDispatcherFaultException;
                if (_debug)
                {
                    ExceptionDetail detail = new ExceptionDetail(ndfe);
                    faultInfo.Fault = Message.CreateMessage(_messageVersion, MessageFault.CreateFault(ndfe.Code, ndfe.Reason, detail), ndfe.Action);
                }
                else
                {
                    faultInfo.Fault = Message.CreateMessage(_messageVersion, ndfe.CreateMessageFault(), ndfe.Action);
                }
            }
        }
 private void ProvideFaultOfLastResort(Exception error, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (faultInfo.Fault == null)
     {
         MessageFault fault;
         FaultCode subCode = new FaultCode("InternalServiceFault", "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher");
         subCode = FaultCode.CreateReceiverFaultCode(subCode);
         string action = "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault";
         if (this.debug)
         {
             faultInfo.DefaultFaultAction = action;
             fault = MessageFault.CreateFault(subCode, new FaultReason(error.Message), new ExceptionDetail(error));
         }
         else
         {
             string text = this.isOnServer ? System.ServiceModel.SR.GetString("SFxInternalServerError") : System.ServiceModel.SR.GetString("SFxInternalCallbackError");
             fault = MessageFault.CreateFault(subCode, new FaultReason(text));
         }
         faultInfo.IsConsideredUnhandled = true;
         faultInfo.Fault = Message.CreateMessage(this.messageVersion, fault, action);
     }
     else if (error != null)
     {
         FaultException exception = error as FaultException;
         if ((((exception != null) && (exception.Fault != null)) && ((exception.Fault.Code != null) && (exception.Fault.Code.SubCode != null))) && ((string.Compare(exception.Fault.Code.SubCode.Namespace, "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher", StringComparison.Ordinal) == 0) && (string.Compare(exception.Fault.Code.SubCode.Name, "InternalServiceFault", StringComparison.Ordinal) == 0)))
         {
             faultInfo.IsConsideredUnhandled = true;
         }
     }
 }
Example #30
0
        internal bool HandleError(Exception error)
        {
            ErrorHandlerFaultInfo dummy = new ErrorHandlerFaultInfo();

            return(HandleError(error, ref dummy));
        }