Ejemplo n.º 1
0
        private RequestContext EndReceiveRequest(RequestContext innerContext)
        {
            RequestContext requestContext = null;

            if (innerContext == null)
            {
                requestContext = null;
            }
            else if (innerContext.RequestMessage == null)
            {
                requestContext = innerContext;
            }
            else if (!_channelInterceptor.DoesRequestIntercept)
            {
                requestContext = innerContext;
            }
            else
            {
                Message wcfMessage = innerContext.RequestMessage;
                // RequestContext wrappedContext;
                InterceptorMessage message = new InterceptorMessage(wcfMessage);
                try
                {
                    this._channelInterceptor.InterceptRequest(message);
                    requestContext = new InterceptorRequestContext(innerContext, message.GetMessage(), _channelInterceptor);
                }
                catch (InterceptorChannelException iifex)
                {
                    WCFLogger.Write(System.Diagnostics.TraceEventType.Warning, "Exception occurred in interceptor");
                    requestContext = this.HandleException(iifex, innerContext, message);
                }
                catch (Exception ex)
                {
                    WCFLogger.Write(System.Diagnostics.TraceEventType.Warning, "Exception occurred in interceptor");
                    InterceptorInternalFailureException iifex = new InterceptorInternalFailureException(ex);
                    requestContext = this.HandleException(iifex, innerContext, message);
                }
            }

            return(requestContext);
        }
Ejemplo n.º 2
0
        private RequestContext HandleException(InterceptorChannelException icex, RequestContext innerContext, InterceptorMessage message)
        {
            RequestContext requestContext;

            WCFLogger.Write(System.Diagnostics.TraceEventType.Start, "Interceptor is starting to handle a thrown exception...");
            try {
                if (_channelInterceptor.DoesFaultOnRequestException)
                {
                    this.SendSoapFault(icex, innerContext, message);
                    requestContext = null;
                }
                else
                {
                    RequestContext wrappedContext = new InterceptorRequestContext(innerContext, message.GetMessage(), _channelInterceptor);
                    object         exceptions     = null;
                    InterceptorChannelExceptionCollection exceptionCollection = null;
                    if (!wrappedContext.RequestMessage.Properties.TryGetValue("Exceptions", out exceptions))
                    {
                        exceptions = new InterceptorChannelExceptionCollection();
                        wrappedContext.RequestMessage.Properties.Add("Exceptions", exceptions);
                    }
                    exceptionCollection = (InterceptorChannelExceptionCollection)exceptions;
                    exceptionCollection.Add(icex);
                    WCFLogger.Write(System.Diagnostics.TraceEventType.Information, "Interceptor added an exception to the message: " + icex.Message);
                    WCFLogger.Write(System.Diagnostics.TraceEventType.Stop, "Interceptor is finished handling the thrown exception.");
                    requestContext = wrappedContext;
                }
            }
            catch (Exception ex)
            {
                WCFLogger.Write(System.Diagnostics.TraceEventType.Error, "An error occurred when trying to handle an exception in the Interceptor: " + ex);
                WCFLogger.Write(System.Diagnostics.TraceEventType.Stop, "Interceptor is finished handling the thrown exception.");
                requestContext = null;
            }

            return(requestContext);
        }