private bool BeginProcessItem(TItem item, WsrmMessageInfo info, TInnerChannel channel, out TReliableChannel reliableChannel, out bool newChannel, out bool dispatch)
        {
            Message faultReply;

            dispatch        = false;
            reliableChannel = default(TReliableChannel);
            newChannel      = false;
            if (info.FaultReply != null)
            {
                faultReply = info.FaultReply;
            }
            else if (info.CreateSequenceInfo == null)
            {
                UniqueId id;
                reliableChannel = base.GetChannel(info, out id);
                if (((TReliableChannel)reliableChannel) != null)
                {
                    return(true);
                }
                if (id == null)
                {
                    this.DisposeItem(item);
                    return(true);
                }
                faultReply = new UnknownSequenceFault(id).CreateMessage(base.MessageVersion, base.ReliableMessagingVersion);
            }
            else
            {
                reliableChannel = base.ProcessCreateSequence(info, channel, out dispatch, out newChannel);
                if (((TReliableChannel)reliableChannel) != null)
                {
                    return(true);
                }
                faultReply = info.FaultReply;
            }
            try
            {
                this.SendReply(faultReply, channel, item);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (!base.HandleException(exception, channel))
                {
                    channel.Abort();
                    return(false);
                }
            }
            finally
            {
                faultReply.Close();
                this.DisposeItem(item);
            }
            return(true);
        }
Example #2
0
        private void HandleReceiveComplete(TItem item, TInnerChannel channel)
        {
            WsrmMessageInfo info = WsrmMessageInfo.Get(base.MessageVersion, base.ReliableMessagingVersion, channel, channel.Session as ISecureConversationSession, this.GetMessage(item));

            if (info.ParsingException != null)
            {
                this.DisposeItem(item);
                channel.Abort();
            }
            else
            {
                TReliableChannel reliableChannel = default(TReliableChannel);
                bool             dispatch        = false;
                bool             newChannel      = false;
                Message          reply           = null;
                if (info.FaultReply != null)
                {
                    reply = info.FaultReply;
                }
                else if (info.CreateSequenceInfo == null)
                {
                    UniqueId id;
                    reliableChannel = base.GetChannel(info, out id);
                    if ((reliableChannel == null) && (id == null))
                    {
                        this.DisposeItem(item);
                        channel.Abort();
                        return;
                    }
                    if (reliableChannel == null)
                    {
                        reply = new UnknownSequenceFault(id).CreateMessage(base.MessageVersion, base.ReliableMessagingVersion);
                    }
                }
                else
                {
                    reliableChannel = base.ProcessCreateSequence(info, channel, out dispatch, out newChannel);
                    if (reliableChannel == null)
                    {
                        reply = info.FaultReply;
                    }
                }
                if (reliableChannel != null)
                {
                    this.ProcessSequencedItem(channel, item, reliableChannel, info, newChannel);
                    if (dispatch)
                    {
                        base.Dispatch();
                    }
                }
                else
                {
                    try
                    {
                        this.SendReply(reply, channel, item);
                        channel.Close();
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        if (DiagnosticUtility.ShouldTraceError)
                        {
                            DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
                        }
                        channel.Abort();
                    }
                    finally
                    {
                        reply.Close();
                        this.DisposeItem(item);
                    }
                }
            }
        }
        public bool ProcessInfo(WsrmMessageInfo info, RequestContext context, bool throwException)
        {
            Exception faultException;

            if (info.ParsingException != null)
            {
                WsrmFault fault;
                if (this.SequenceID != null)
                {
                    string faultReason = System.ServiceModel.SR.GetString("CouldNotParseWithAction", new object[] { info.Action });
                    fault = SequenceTerminatedFault.CreateProtocolFault(this.SequenceID, faultReason, null);
                }
                else
                {
                    fault = null;
                }
                faultException = new ProtocolException(System.ServiceModel.SR.GetString("MessageExceptionOccurred"), info.ParsingException);
                this.OnLocalFault(throwException ? null : faultException, fault, context);
            }
            else if (info.FaultReply != null)
            {
                faultException = info.FaultException;
                this.OnLocalFault(throwException ? null : faultException, info.FaultReply, context);
            }
            else if (((info.WsrmHeaderFault != null) && (info.WsrmHeaderFault.SequenceID != this.InputID)) && (info.WsrmHeaderFault.SequenceID != this.OutputID))
            {
                faultException = new ProtocolException(System.ServiceModel.SR.GetString("WrongIdentifierFault", new object[] { FaultException.GetSafeReasonText(info.WsrmHeaderFault.Reason) }));
                this.OnLocalFault(throwException ? null : faultException, (Message)null, context);
            }
            else
            {
                if (info.FaultInfo == null)
                {
                    return(true);
                }
                if (this.isSessionClosed)
                {
                    UnknownSequenceFault faultInfo = info.FaultInfo as UnknownSequenceFault;
                    if (faultInfo != null)
                    {
                        UniqueId sequenceID = faultInfo.SequenceID;
                        if (((this.OutputID != null) && (this.OutputID == sequenceID)) || ((this.InputID != null) && (this.InputID == sequenceID)))
                        {
                            if (this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
                            {
                                info.Message.Close();
                                return(false);
                            }
                            if (this.settings.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11)
                            {
                                throw Fx.AssertAndThrow("Unknown version.");
                            }
                            return(true);
                        }
                    }
                }
                faultException = info.FaultException;
                if (context != null)
                {
                    context.Close();
                }
                this.OnRemoteFault(throwException ? null : faultException);
            }
            info.Message.Close();
            if (throwException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(faultException);
            }
            return(false);
        }