private void ThrowIfFaultMessage(Message wcfMessage)
            {
                Exception exception;

                if (wcfMessage.IsFault)
                {
                    MessagingClientEtwProvider.TraceClient(() => {
                    });
                    string         action       = wcfMessage.Headers.Action;
                    MessageFault   messageFault = MessageFault.CreateFault(wcfMessage, 65536);
                    FaultConverter property     = this.innerChannel.GetProperty <FaultConverter>();
                    if (property == null || !property.TryCreateException(wcfMessage, messageFault, out exception))
                    {
                        if (!messageFault.HasDetail)
                        {
                            throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsWarning(new FaultException(messageFault, action), null);
                        }
                        ExceptionDetail detail = messageFault.GetDetail <ExceptionDetail>();
                        if (!this.clientMode && string.Equals(detail.Type, typeof(CommunicationException).FullName, StringComparison.Ordinal))
                        {
                            MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteRuntimeChannelFaulting(this.innerChannel.GetType().Name, this.innerChannel.LocalAddress.Uri.AbsoluteUri, this.innerChannel.RemoteAddress.Uri.AbsoluteUri, this.innerChannel.Via.AbsoluteUri, this.innerChannel.Session.Id, string.Concat("ThrowIfFaultMessage: Received CommunicationException as fault message. ", detail.ToString())));
                            base.Fault();
                        }
                        if (!this.includeExceptionDetails)
                        {
                            throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsInformation(new FaultException <ExceptionDetailNoStackTrace>(new ExceptionDetailNoStackTrace(detail, true), messageFault.Reason, messageFault.Code, action), null);
                        }
                        throw Microsoft.ServiceBus.Messaging.FxTrace.Exception.AsInformation(new FaultException <ExceptionDetail>(detail, messageFault.Reason, messageFault.Code, action), null);
                    }
                    throw Fx.Exception.AsWarning(exception, null);
                }
            }
Beispiel #2
0
        Exception DeserializeFault(Message inMessage, FaultConverter faultConverter)
        {
            // Reproduce logic in ClientOperationFormatterHelper

            MessageFault messageFault = MessageFault.CreateFault(inMessage, TransportDefaults.MaxFaultSize);
            string       action       = inMessage.Headers.Action;

            if (action == inMessage.Version.Addressing.DefaultFaultAction)
            {
                action = null;
            }

            Exception exception = null;

            if (faultConverter != null)
            {
                faultConverter.TryCreateException(inMessage, messageFault, out exception);
            }

            if (exception == null)
            {
                exception = this.FaultFormatter.Deserialize(messageFault, action);
            }

            if (inMessage.State != MessageState.Created)
            {
                inMessage.Close();
            }

            return(exception);
        }
        bool ProcessErrorWithHandlers(IChannel ch, Exception ex, out Message res)
        {
            res = null;

            foreach (var eh in owner.ErrorHandlers)
            {
                if (eh.HandleError(ex))
                {
                    return(true);                            // error is handled appropriately.
                }
            }
            Logger.Error("An error occured, to be handled", ex);

            foreach (var eh in owner.ErrorHandlers)
            {
                eh.ProvideFault(ex, owner.MessageVersion, ref res);
            }
            if (res == null)
            {
                var conv = ch.GetProperty <FaultConverter> () ?? FaultConverter.GetDefaultFaultConverter(owner.MessageVersion);
                if (!conv.TryCreateFaultMessage(ex, out res))
                {
                    res = Message.CreateMessage(owner.MessageVersion, new FaultCode("Receiver"), ex.Message, owner.MessageVersion.Addressing.FaultNamespace);
                }
            }

            return(false);
        }
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            Exception       ex = mrc.ProcessingException;
            DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

            //invoke all user handlers
            ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;

            foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
            {
                if (handler.HandleError(ex))
                {
                    break;
                }
            }

            FaultConverter fc  = FaultConverter.GetDefaultFaultConverter(dispatchRuntime.ChannelDispatcher.MessageVersion);
            Message        res = null;

            if (!fc.TryCreateFaultMessage(ex, out res))
            {
                throw ex;
            }
            mrc.ReplyMessage = res;
            if (duplex != null)
            {
                mrc.Reply(duplex, true);
            }
            else
            {
                mrc.Reply(true);
            }
            return(false);
        }
Beispiel #5
0
 /// <summary>
 /// Gets the property.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public override T GetProperty <T>()
 {
     if (typeof(T) == typeof(FaultConverter))
     {
         return(FaultConverter.GetDefaultFaultConverter(MessageVersion.Soap12WSAddressing10) as T);
     }
     return(base.GetProperty <T>());
 }
Beispiel #6
0
        protected override void Execute(CodeActivityContext context)
        {
            Message inMessage = this.Message.Get(context);

            if (inMessage == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NullReplyMessageContractMismatch));
            }
            if (inMessage.IsFault)
            {
                FaultConverter faultConverter = FaultConverter.GetDefaultFaultConverter(inMessage.Version);
                Exception      exception      = DeserializeFault(inMessage, faultConverter);

                // We simply throw the exception
                throw FxTrace.Exception.AsError(exception);
            }
            else
            {
                object[] outObjects;
                if (this.parameters != null)
                {
                    outObjects = new object[this.parameters.Count];
                }
                else
                {
                    outObjects = Constants.EmptyArray;
                }

                object returnValue = this.Formatter.DeserializeReply(inMessage, outObjects);

                if (this.Result != null)
                {
                    this.Result.Set(context, returnValue);
                }

                if (parameters != null)
                {
                    for (int i = 0; i < this.parameters.Count; i++)
                    {
                        OutArgument outArgument = this.parameters[i];
                        Fx.Assert(outArgument != null, "Parameter cannot be null");

                        object obj = outObjects[i];
                        if (obj == null)
                        {
                            obj = ProxyOperationRuntime.GetDefaultParameterValue(outArgument.ArgumentType);
                        }

                        outArgument.Set(context, obj);
                    }
                }
            }
        }
Beispiel #7
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);
         //}
     }
     ProvideFaultOfLastResort(e, ref faultInfo);
 }
 internal void ProvideFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
 {
     this.ProvideWellKnownFault(e, faultConverter, ref faultInfo);
     for (int i = 0; i < this.handlers.Length; i++)
     {
         Message fault = faultInfo.Fault;
         this.handlers[i].ProvideFault(e, this.messageVersion, ref fault);
         faultInfo.Fault = fault;
         if (TD.FaultProviderInvokedIsEnabled())
         {
             TD.FaultProviderInvoked(this.handlers[i].GetType().FullName, e.Message);
         }
     }
     this.ProvideFaultOfLastResort(e, ref faultInfo);
 }
Beispiel #9
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 (WcfEventSource.Instance.FaultProviderInvokedIsEnabled())
         {
             WcfEventSource.Instance.FaultProviderInvoked(_handlers[i].GetType().FullName, e.Message);
         }
     }
     this.ProvideFaultOfLastResort(e, ref faultInfo);
 }
Beispiel #10
0
        internal void ProvideFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior errorBehavior;

            lock (base.ThisLock)
            {
                if (this.errorBehavior != null)
                {
                    errorBehavior = this.errorBehavior;
                }
                else
                {
                    errorBehavior = new ErrorBehavior(this);
                }
            }
            errorBehavior.ProvideFault(e, faultConverter, ref faultInfo);
        }
Beispiel #11
0
        // TODO: Move this functionality somewhere else as this class is now OM only
        internal void ProvideFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
        {
            ErrorBehavior behavior;

            lock (ThisLock)
            {
                if (_errorBehavior != null)
                {
                    behavior = _errorBehavior;
                }
                else
                {
                    behavior = new ErrorBehavior(this);
                }
            }

            behavior.ProvideFault(e, faultConverter, ref faultInfo);
        }
        protected override void Execute(CodeActivityContext context)
        {
            object[] emptyArray;
            System.ServiceModel.Channels.Message inMessage = this.Message.Get(context);
            if (inMessage == null)
            {
                throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.NullReplyMessageContractMismatch));
            }
            if (inMessage.IsFault)
            {
                FaultConverter defaultFaultConverter = FaultConverter.GetDefaultFaultConverter(inMessage.Version);
                Exception      exception             = this.DeserializeFault(inMessage, defaultFaultConverter);
                throw System.ServiceModel.Activities.FxTrace.Exception.AsError(exception);
            }
            if (this.parameters != null)
            {
                emptyArray = new object[this.parameters.Count];
            }
            else
            {
                emptyArray = System.ServiceModel.Activities.Constants.EmptyArray;
            }
            object obj2 = this.Formatter.DeserializeReply(inMessage, emptyArray);

            if (this.Result != null)
            {
                this.Result.Set(context, obj2);
            }
            if (this.parameters != null)
            {
                for (int i = 0; i < this.parameters.Count; i++)
                {
                    OutArgument argument = this.parameters[i];
                    object      defaultParameterValue = emptyArray[i];
                    if (defaultParameterValue == null)
                    {
                        defaultParameterValue = ProxyOperationRuntime.GetDefaultParameterValue(argument.ArgumentType);
                    }
                    argument.Set(context, defaultParameterValue);
                }
            }
        }
        protected override bool OnTryCreateFaultMessage(Exception exception, out Message message)
        {
            if (_innerChannel == null)
            {
                message = null;
                return(false);
            }

            FaultConverter inner = _innerChannel.GetProperty <FaultConverter>();

            if (inner != null)
            {
                return(inner.TryCreateFaultMessage(exception, out message));
            }
            else
            {
                message = null;
                return(false);
            }
        }
        protected override bool OnTryCreateException(Message message, MessageFault fault, out Exception exception)
        {
            if (_innerChannel == null)
            {
                exception = null;
                return(false);
            }

            FaultConverter inner = _innerChannel.GetProperty <FaultConverter>();

            if (inner != null)
            {
                return(inner.TryCreateException(message, fault, out exception));
            }
            else
            {
                exception = null;
                return(false);
            }
        }
Beispiel #15
0
 public override void Reply(Message message, TimeSpan timeout)
 {
     try {
         if (!message.IsFault && message.Headers.Action != Constants.WstIssueReplyAction)
         {
             message = SecureMessage(message);
         }
         source.Reply(message, timeout);
     } catch (Exception ex) {
         FaultConverter fc = FaultConverter.GetDefaultFaultConverter(msg.Version);
         Message        fault;
         if (fc.TryCreateFaultMessage(ex, out fault))
         {
             source.Reply(fault, timeout);
         }
         else
         {
             throw;
         }
     }
 }
Beispiel #16
0
 private void ProvideWellKnownFault(Exception e, FaultConverter faultConverter, ref ErrorHandlerFaultInfo faultInfo)
 {
     if (faultConverter != null && faultConverter.TryCreateFaultMessage(e, out Message 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 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);
                }
            }
        }
        void ProcessInputCore(IInputChannel input, Message message)
        {
            bool isReply = message != null && Contract.Operations.Any(od => (od.DeclaringContract.CallbackContractType == od.DeclaringContract.ContractType || !od.InCallbackContract) && od.Messages.Any(md => md.Action == message.Headers.Action));

            if (isReply)
            {
                if (ReplyHandlerQueue.Count > 0)
                {
                    if (isReply)
                    {
                        var h = ReplyHandlerQueue.Dequeue();
                        h(message);
                        return;
                    }
                }
            }

            if (message.IsFault)
            {
                Exception ex;
                var       mf = MessageFault.CreateFault(message, 0x10000);
                if (FaultConverter.GetDefaultFaultConverter(message.Version).TryCreateException(message, mf, out ex))                           // FIXME: get maxMessageSize somehow
                {
                    throw ex;
                }
                else
                {
                    throw new FaultException(mf);
                }
            }

            if (!MessageMatchesEndpointDispatcher(message, Runtime.CallbackDispatchRuntime.EndpointDispatcher))
            {
                throw new EndpointNotFoundException(String.Format("The request message has the target '{0}' with action '{1}' which is not reachable in this service contract", message.Headers.To, message.Headers.Action));
            }
            new InputOrReplyRequestProcessor(Runtime.CallbackDispatchRuntime, input).ProcessInput(message);
        }
Beispiel #19
0
        protected override bool ProcessRequest(MessageProcessingContext mrc)
        {
            Exception       ex = mrc.ProcessingException;
            DispatchRuntime dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;

            //invoke all user handlers
            ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;

            foreach (IErrorHandler handler in channelDispatcher.ErrorHandlers)
            {
                if (handler.HandleError(ex))
                {
                    break;
                }
            }

            // FIXME: remove them. FaultConverter also covers errors like EndpointNotFoundException, which this handler never covers. And checking converter twice is extraneous, so this part is just extraneous.
            // FIXME: actually everything is done in OperationInvokerHandler now...
            FaultConverter fc  = FaultConverter.GetDefaultFaultConverter(dispatchRuntime.ChannelDispatcher.MessageVersion);
            Message        res = null;

            if (!fc.TryCreateFaultMessage(ex, out res))
            {
                throw ex;
            }
            mrc.ReplyMessage = res;

            if (duplex != null)
            {
                mrc.Reply(duplex, true);
            }
            else
            {
                mrc.Reply(true);
            }
            return(false);
        }
Beispiel #20
0
        object Request(OperationDescription od, bool isAsync, ref object [] parameters, OperationContext context)
        {
            ClientOperation op = runtime.Operations [od.Name];

            object [] inspections = new object [runtime.MessageInspectors.Count];
            Message   req         = CreateRequest(op, parameters, context);

            for (int i = 0; i < inspections.Length; i++)
            {
                inspections [i] = runtime.MessageInspectors [i].BeforeSendRequest(ref req, this);
            }

            Message res = Request(req, OperationTimeout);

            if (res.IsFault)
            {
                var          resb  = res.CreateBufferedCopy(runtime.MaxFaultSize);
                MessageFault fault = MessageFault.CreateFault(resb.CreateMessage(), runtime.MaxFaultSize);
                var          conv  = OperationChannel.GetProperty <FaultConverter> () ?? FaultConverter.GetDefaultFaultConverter(res.Version);
                Exception    ex;
                if (!conv.TryCreateException(resb.CreateMessage(), fault, out ex))
                {
                    if (fault.HasDetail)
                    {
                        Type detailType           = typeof(ExceptionDetail);
                        var  freader              = fault.GetReaderAtDetailContents();
                        DataContractSerializer ds = null;
                        foreach (var fci in op.FaultContractInfos)
                        {
                            if (res.Headers.Action == fci.Action || fci.Serializer.IsStartObject(freader))
                            {
                                detailType = fci.Detail;
                                ds         = fci.Serializer;
                                break;
                            }
                        }
                        if (ds == null)
                        {
                            ds = new DataContractSerializer(detailType);
                        }
                        var detail = ds.ReadObject(freader);
                        ex = (Exception)Activator.CreateInstance(typeof(FaultException <>).MakeGenericType(detailType), new object [] { detail, fault.Reason, fault.Code, res.Headers.Action });
                    }

                    if (ex == null)
                    {
                        ex = new FaultException(fault);
                    }
                }
                throw ex;
            }

            for (int i = 0; i < inspections.Length; i++)
            {
                runtime.MessageInspectors [i].AfterReceiveReply(ref res, inspections [i]);
            }

            if (!op.DeserializeReply)
            {
                return(res);
            }

            if (isAsync && od.EndMethod != null)
            {
                var endParams = od.EndMethod.GetParameters();
                parameters = new object [endParams.Length - 1];
            }

            return(op.Formatter.DeserializeReply(res, parameters));
        }
        private Exception DeserializeFault(System.ServiceModel.Channels.Message inMessage, FaultConverter faultConverter)
        {
            MessageFault fault  = MessageFault.CreateFault(inMessage, 0x10000);
            string       action = inMessage.Headers.Action;

            if (action == inMessage.Version.Addressing.DefaultFaultAction)
            {
                action = null;
            }
            Exception exception = null;

            if (faultConverter != null)
            {
                faultConverter.TryCreateException(inMessage, fault, out exception);
            }
            if (exception == null)
            {
                exception = this.FaultFormatter.Deserialize(fault, action);
            }
            if (inMessage.State != MessageState.Created)
            {
                inMessage.Close();
            }
            return(exception);
        }
Beispiel #22
0
 public static List <Fault> GetFaultByBuilding(int buildingId)
 {
     return(FaultConverter.ListToDTO(FaultDAL.GetFaultByBuilding(buildingId)));
 }
Beispiel #23
0
 public static void UpdateFaultStatus(Fault f)
 {
     FaultDAL.UpdateStatus(FaultConverter.ToDAL(f));
 }
Beispiel #24
0
 public static void AddFault(Fault fault)
 {
     FaultDAL.Add(FaultConverter.ToDAL(fault));
 }
Beispiel #25
0
 public static List <Fault> GetAll()
 {
     return(FaultConverter.ListToDTO(FaultDAL.Get()));
 }
Beispiel #26
0
 public static Fault GetById(int id)
 {
     return(FaultConverter.ToDTO(FaultDAL.GetById(id)));
 }
Beispiel #27
0
        /// <summary>
        /// Converts fault to exception and throws it
        /// </summary>
        /// <param name="response">Response message</param>
        /// <param name="fault">Fault message</param>
        /// <param name="action">SOAP Action</param>
        /// <param name="version">Message Version</param>
        private static void ThrowIfFaultUnderstood(
            Message response,
            MessageFault fault,
            string action,
            MessageVersion version)
        {
            Exception      exception;
            bool           isSenderFault;
            bool           isReceiverFault;
            FaultCode      subCode;
            FaultConverter faultConverter = FaultConverter.GetDefaultFaultConverter(version);

            if (faultConverter.TryCreateException(response, fault, out exception))
            {
                throw exception;
            }

            if (version.Envelope == EnvelopeVersion.Soap11)
            {
                isSenderFault   = true;
                isReceiverFault = true;
                subCode         = fault.Code;
            }
            else
            {
                isSenderFault   = fault.Code.IsSenderFault;
                isReceiverFault = fault.Code.IsReceiverFault;
                subCode         = fault.Code.SubCode;
            }

            if ((subCode != null) && (subCode.Namespace != null))
            {
                if (isSenderFault)
                {
                    if (string.Compare(subCode.Namespace, "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher", StringComparison.Ordinal) == 0)
                    {
                        if (string.Compare(subCode.Name, "SessionTerminated", StringComparison.Ordinal) == 0)
                        {
                            throw new ChannelTerminatedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                        }

                        if (string.Compare(subCode.Name, "TransactionAborted", StringComparison.Ordinal) == 0)
                        {
                            throw new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                        }
                    }
                }

                if (isReceiverFault && (string.Compare(subCode.Namespace, "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher", StringComparison.Ordinal) == 0))
                {
                    if (string.Compare(subCode.Name, "InternalServiceFault", StringComparison.Ordinal) == 0)
                    {
                        if (fault.HasDetail)
                        {
                            ExceptionDetail detail = fault.GetDetail <ExceptionDetail>();
                            throw new FaultException <ExceptionDetail>(detail, fault.Reason, fault.Code, action);
                        }

                        throw new FaultException(fault, action);
                    }

                    if (string.Compare(subCode.Name, "DeserializationFailed", StringComparison.Ordinal) == 0)
                    {
                        throw new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text);
                    }
                }
            }

            throw new FaultException(fault);
        }