protected override void ProcessMessage(WsrmMessageInfo info)
 {
     if (base.ReliableSession.ProcessInfo(info, null) && base.ReliableSession.VerifyDuplexProtocolElements(info, null))
     {
         if (info.CreateSequenceInfo == null)
         {
             base.ProcessDuplexMessage(info);
         }
         else
         {
             EndpointAddress address;
             if (WsrmUtilities.ValidateCreateSequence <IDuplexSessionChannel>(info, this.listener, base.Binder.Channel, out address))
             {
                 Message response = WsrmUtilities.CreateCreateSequenceResponse(base.Settings.MessageVersion, base.Settings.ReliableMessagingVersion, true, info.CreateSequenceInfo, base.Settings.Ordered, base.ReliableSession.InputID, address);
                 using (info.Message)
                 {
                     using (response)
                     {
                         if (((IServerReliableChannelBinder)base.Binder).AddressResponse(info.Message, response))
                         {
                             base.Binder.Send(response, base.DefaultSendTimeout);
                         }
                     }
                     return;
                 }
             }
             base.ReliableSession.OnLocalFault(info.FaultException, info.FaultReply, null);
         }
     }
 }
        private void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }
            ReliableRequestor requestor = close ? this.closeRequestor : this.terminateRequestor;

            if (requestor.GetInfo() == null)
            {
                try
                {
                    WsrmMessageInfo info = WsrmMessageInfo.Get(this.Settings.MessageVersion, this.Settings.ReliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(), reply);
                    this.ReliableSession.ProcessInfo(info, null, true);
                    this.ReliableSession.VerifyDuplexProtocolElements(info, null, true);
                    WsrmFault fault = close ? WsrmUtilities.ValidateCloseSequenceResponse(this.session, requestor.MessageId, info, this.connection.Last) : WsrmUtilities.ValidateTerminateSequenceResponse(this.session, requestor.MessageId, info, this.connection.Last);
                    if (fault != null)
                    {
                        this.ReliableSession.OnLocalFault(null, fault, null);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                    }
                }
                finally
                {
                    reply.Close();
                }
            }
        }
        public static WsrmFault ValidateFinalAck(ChannelReliableSession session, WsrmMessageInfo info, long last)
        {
            WsrmAcknowledgmentInfo acknowledgementInfo = info.AcknowledgementInfo;
            WsrmFault fault = ValidateFinalAckExists(session, acknowledgementInfo);

            if (fault != null)
            {
                return(fault);
            }
            SequenceRangeCollection ranges = acknowledgementInfo.Ranges;

            if (last == 0L)
            {
                if (ranges.Count == 0)
                {
                    return(null);
                }
            }
            else if (ranges.Count == 1)
            {
                SequenceRange range = ranges[0];
                if (range.Lower == 1L)
                {
                    SequenceRange range2 = ranges[0];
                    if (range2.Upper == last)
                    {
                        return(null);
                    }
                }
            }
            return(new InvalidAcknowledgementFault(session.OutputID, acknowledgementInfo.Ranges));
        }
        public static CreateSequenceInfo ReadMessage(MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, ISecureConversationSession securitySession, Message message, MessageHeaders headers)
        {
            CreateSequenceInfo info;

            if (message.IsEmpty)
            {
                string  reason     = System.ServiceModel.SR.GetString("NonEmptyWsrmMessageIsEmpty", new object[] { WsrmIndex.GetCreateSequenceActionString(reliableMessagingVersion) });
                Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
            }
            using (XmlDictionaryReader reader = message.GetReaderAtBodyContents())
            {
                info = CreateSequence.Create(messageVersion, reliableMessagingVersion, securitySession, reader);
                message.ReadFromBodyContentsToEnd(reader);
            }
            info.SetMessageId(messageVersion, headers);
            info.SetReplyTo(messageVersion, headers);
            if (info.AcksTo.Uri != info.ReplyTo.Uri)
            {
                string  str2     = System.ServiceModel.SR.GetString("CSRefusedAcksToMustEqualReplyTo");
                Message message3 = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, str2);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(message3, str2, new ProtocolException(str2)));
            }
            info.to = message.Headers.To;
            if ((info.to == null) && (messageVersion.Addressing == AddressingVersion.WSAddressing10))
            {
                info.to = messageVersion.Addressing.AnonymousUri;
            }
            return(info);
        }
        protected override bool HandleReceiveComplete(IAsyncResult result)
        {
            RequestContext context;

            if (!base.Binder.EndTryReceive(result, out context))
            {
                return(true);
            }
            if (context == null)
            {
                bool flag2 = false;
                lock (base.ThisLock)
                {
                    flag2 = base.Connection.Terminate();
                }
                if (!flag2 && (base.Binder.State == CommunicationState.Opened))
                {
                    Exception e = new CommunicationException(System.ServiceModel.SR.GetString("EarlySecurityClose"));
                    base.ReliableSession.OnLocalFault(e, (Message)null, null);
                }
                return(false);
            }
            WsrmMessageInfo info = WsrmMessageInfo.Get(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion, base.Binder.Channel, base.Binder.GetInnerSession(), context.RequestMessage);

            base.StartReceiving(false);
            this.ProcessRequest(context, info);
            return(false);
        }
 protected override void ProcessMessage(WsrmMessageInfo info)
 {
     if (base.ReliableSession.ProcessInfo(info, null) && base.ReliableSession.VerifyDuplexProtocolElements(info, null))
     {
         base.ProcessDuplexMessage(info);
     }
 }
 protected override WsrmFault VerifySimplexProtocolElements(WsrmMessageInfo info)
 {
     if ((info.AcknowledgementInfo != null) && (info.AcknowledgementInfo.SequenceID != base.OutputID))
     {
         return(new UnknownSequenceFault(info.AcknowledgementInfo.SequenceID));
     }
     if (info.AckRequestedInfo != null)
     {
         return(SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedAckRequested"), System.ServiceModel.SR.GetString("UnexpectedAckRequested")));
     }
     if (info.CreateSequenceInfo != null)
     {
         return(SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCS"), System.ServiceModel.SR.GetString("UnexpectedCS")));
     }
     if (info.SequencedMessageInfo != null)
     {
         return(new UnknownSequenceFault(info.SequencedMessageInfo.SequenceID));
     }
     if (info.TerminateSequenceInfo != null)
     {
         if (base.Settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
         {
             return(SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedTerminateSequence"), System.ServiceModel.SR.GetString("UnexpectedTerminateSequence")));
         }
         if (info.TerminateSequenceInfo.Identifier == base.OutputID)
         {
             return(null);
         }
         return(new UnknownSequenceFault(info.TerminateSequenceInfo.Identifier));
     }
     if (info.TerminateSequenceResponseInfo != null)
     {
         WsrmUtilities.AssertWsrm11(base.Settings.ReliableMessagingVersion);
         if (info.TerminateSequenceResponseInfo.Identifier == base.OutputID)
         {
             return(null);
         }
         return(new UnknownSequenceFault(info.TerminateSequenceResponseInfo.Identifier));
     }
     if (info.CloseSequenceInfo != null)
     {
         WsrmUtilities.AssertWsrm11(base.Settings.ReliableMessagingVersion);
         if (info.CloseSequenceInfo.Identifier == base.OutputID)
         {
             return(SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnsupportedClose"), System.ServiceModel.SR.GetString("UnsupportedCloseExceptionString")));
         }
         return(new UnknownSequenceFault(info.CloseSequenceInfo.Identifier));
     }
     if (info.CloseSequenceResponseInfo == null)
     {
         return(null);
     }
     WsrmUtilities.AssertWsrm11(base.Settings.ReliableMessagingVersion);
     if (info.CloseSequenceResponseInfo.Identifier == base.OutputID)
     {
         return(null);
     }
     return(new UnknownSequenceFault(info.CloseSequenceResponseInfo.Identifier));
 }
 private void EndProcessItem(TItem item, WsrmMessageInfo info, TReliableChannel channel, bool dispatch)
 {
     this.ProcessSequencedItem(channel, item, info);
     if (dispatch)
     {
         base.Dispatch();
     }
 }
        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);
        }
 public override void SetInfo(WsrmMessageInfo info)
 {
     lock (this.ThisLock)
     {
         if (!this.replied && (this.replyInfo == null))
         {
             this.replyInfo = info;
         }
     }
 }
 public override void SetInfo(WsrmMessageInfo info)
 {
     lock (this.ThisLock)
     {
         if (!this.replied && (this.replyInfo == null))
         {
             this.replyInfo = info;
         }
     }
 }
 public override void SetInfo(WsrmMessageInfo info)
 {
     lock (this.ThisLock)
     {
         if (this.replied || (this.replyInfo != null))
         {
             return;
         }
         this.replyInfo = info;
     }
     this.replyHandle.Set();
 }
 protected override WsrmFault VerifySimplexProtocolElements(WsrmMessageInfo info)
 {
     if (info.AcknowledgementInfo != null)
     {
         return SequenceTerminatedFault.CreateProtocolFault(base.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedAcknowledgement"), System.ServiceModel.SR.GetString("UnexpectedAcknowledgement"));
     }
     if ((info.AckRequestedInfo != null) && (info.AckRequestedInfo.SequenceID != base.InputID))
     {
         return new UnknownSequenceFault(info.AckRequestedInfo.SequenceID);
     }
     if (info.CreateSequenceResponseInfo != null)
     {
         return SequenceTerminatedFault.CreateProtocolFault(base.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCSR"), System.ServiceModel.SR.GetString("UnexpectedCSR"));
     }
     if ((info.SequencedMessageInfo != null) && (info.SequencedMessageInfo.SequenceID != base.InputID))
     {
         return new UnknownSequenceFault(info.SequencedMessageInfo.SequenceID);
     }
     if ((info.TerminateSequenceInfo != null) && (info.TerminateSequenceInfo.Identifier != base.InputID))
     {
         return new UnknownSequenceFault(info.TerminateSequenceInfo.Identifier);
     }
     if (info.TerminateSequenceResponseInfo != null)
     {
         WsrmUtilities.AssertWsrm11(base.Settings.ReliableMessagingVersion);
         if (info.TerminateSequenceResponseInfo.Identifier == base.InputID)
         {
             return SequenceTerminatedFault.CreateProtocolFault(base.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedTerminateSequenceResponse"), System.ServiceModel.SR.GetString("UnexpectedTerminateSequenceResponse"));
         }
         return new UnknownSequenceFault(info.TerminateSequenceResponseInfo.Identifier);
     }
     if (info.CloseSequenceInfo != null)
     {
         WsrmUtilities.AssertWsrm11(base.Settings.ReliableMessagingVersion);
         if (info.CloseSequenceInfo.Identifier == base.InputID)
         {
             return null;
         }
         return new UnknownSequenceFault(info.CloseSequenceInfo.Identifier);
     }
     if (info.CloseSequenceResponseInfo == null)
     {
         return null;
     }
     WsrmUtilities.AssertWsrm11(base.Settings.ReliableMessagingVersion);
     if (info.CloseSequenceResponseInfo.Identifier == base.InputID)
     {
         return SequenceTerminatedFault.CreateProtocolFault(base.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCloseSequenceResponse"), System.ServiceModel.SR.GetString("UnexpectedCloseSequenceResponse"));
     }
     return new UnknownSequenceFault(info.CloseSequenceResponseInfo.Identifier);
 }
        private bool HandleReceiveComplete(TItem item, TInnerChannel channel)
        {
            Message          message = null;
            TReliableChannel local;
            bool             flag;
            bool             flag2;

            try
            {
                message = this.GetMessage(item);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (!base.HandleException(exception, this))
                {
                    throw;
                }
                item.Dispose();
                return(true);
            }
            WsrmMessageInfo info = WsrmMessageInfo.Get(base.MessageVersion, base.ReliableMessagingVersion, channel, null, message);

            if (info.ParsingException != null)
            {
                this.DisposeItem(item);
                return(true);
            }
            if (!this.BeginProcessItem(item, info, channel, out local, out flag, out flag2))
            {
                return(false);
            }
            if (local == null)
            {
                this.DisposeItem(item);
                return(true);
            }
            if (flag2 || !flag)
            {
                this.StartReceiving(channel, false);
                this.EndProcessItem(item, info, local, flag2);
                return(false);
            }
            this.EndProcessItem(item, info, local, flag2);
            return(true);
        }
Exemple #15
0
 public void ProcessDemuxedMessage(WsrmMessageInfo info)
 {
     try
     {
         this.ProcessMessage(info);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.ReliableSession.OnUnknownException(exception);
     }
 }
 public void ProcessDemuxedRequest(RequestContext context, WsrmMessageInfo info)
 {
     try
     {
         this.ProcessRequest(context, info);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.ReliableSession.OnUnknownException(exception);
     }
 }
 public void ProcessDemuxedRequest(RequestContext context, WsrmMessageInfo info)
 {
     try
     {
         this.ProcessRequest(context, info);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.ReliableSession.OnUnknownException(exception);
     }
 }
 protected override WsrmFault VerifyDuplexProtocolElements(WsrmMessageInfo info)
 {
     WsrmFault fault = base.VerifyDuplexProtocolElements(info);
     if (fault != null)
     {
         return fault;
     }
     if ((info.CreateSequenceInfo != null) && (info.CreateSequenceInfo.OfferIdentifier != base.OutputID))
     {
         return SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCSOfferId"), System.ServiceModel.SR.GetString("UnexpectedCSOfferId"));
     }
     if (info.CreateSequenceResponseInfo != null)
     {
         return SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCSR"), System.ServiceModel.SR.GetString("UnexpectedCSR"));
     }
     return null;
 }
        public bool VerifyDuplexProtocolElements(WsrmMessageInfo info, RequestContext context, bool throwException)
        {
            WsrmFault fault = this.VerifyDuplexProtocolElements(info);

            if (fault == null)
            {
                return(true);
            }
            if (throwException)
            {
                Exception exception = fault.CreateException();
                this.OnLocalFault(null, fault, context);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
            }
            this.OnLocalFault(fault.CreateException(), fault, context);
            return(false);
        }
        private void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }
            ReliableMessagingVersion reliableMessagingVersion = this.settings.ReliableMessagingVersion;

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
            {
                if (close)
                {
                    throw Fx.AssertAndThrow("Close does not exist in Feb2005.");
                }
                reply.Close();
            }
            else
            {
                if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
                {
                    if (this.closeRequestor.GetInfo() != null)
                    {
                        return;
                    }
                    try
                    {
                        WsrmMessageInfo info = WsrmMessageInfo.Get(this.settings.MessageVersion, reliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(), reply);
                        this.session.ProcessInfo(info, null, true);
                        this.session.VerifyDuplexProtocolElements(info, null, true);
                        WsrmFault fault = close ? WsrmUtilities.ValidateCloseSequenceResponse(this.session, this.closeRequestor.MessageId, info, this.connection.Last) : WsrmUtilities.ValidateTerminateSequenceResponse(this.session, this.terminateRequestor.MessageId, info, this.connection.Last);
                        if (fault != null)
                        {
                            this.session.OnLocalFault(null, fault, null);
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                        }
                        return;
                    }
                    finally
                    {
                        reply.Close();
                    }
                }
                throw Fx.AssertAndThrow("Reliable messaging version not supported.");
            }
        }
Exemple #21
0
 protected TReliableChannel GetChannel(WsrmMessageInfo info, out UniqueId id)
 {
     id = WsrmUtilities.GetInputId(info);
     lock (base.ThisLock)
     {
         TReliableChannel local = default(TReliableChannel);
         if (((id == null) || !this.channelsByInput.TryGetValue(id, out local)) && this.Duplex)
         {
             UniqueId outputId = WsrmUtilities.GetOutputId(base.ReliableMessagingVersion, info);
             if (outputId != null)
             {
                 id = outputId;
                 this.channelsByOutput.TryGetValue(id, out local);
             }
         }
         return(local);
     }
 }
Exemple #22
0
        protected override WsrmFault VerifyDuplexProtocolElements(WsrmMessageInfo info)
        {
            WsrmFault fault = base.VerifyDuplexProtocolElements(info);

            if (fault != null)
            {
                return(fault);
            }
            if ((info.CreateSequenceInfo != null) && (info.CreateSequenceInfo.OfferIdentifier != base.OutputID))
            {
                return(SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCSOfferId"), System.ServiceModel.SR.GetString("UnexpectedCSOfferId")));
            }
            if (info.CreateSequenceResponseInfo != null)
            {
                return(SequenceTerminatedFault.CreateProtocolFault(base.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCSR"), System.ServiceModel.SR.GetString("UnexpectedCSR")));
            }
            return(null);
        }
        private void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                // In the close case, the requestor is configured to throw TimeoutException instead of returning null.
                // In the terminate case, this value can be null, but the caller should not call this method.
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }

            ReliableRequestor requestor = close ? _closeRequestor : _terminateRequestor;
            WsrmMessageInfo   info      = requestor.GetInfo();

            // Some other thread has verified and cleaned up the reply, no more work to do.
            if (info != null)
            {
                return;
            }

            try
            {
                info = WsrmMessageInfo.Get(Settings.MessageVersion, Settings.ReliableMessagingVersion,
                                           _binder.Channel, _binder.GetInnerSession(), reply);
                ReliableSession.ProcessInfo(info, null, true);
                ReliableSession.VerifyDuplexProtocolElements(info, null, true);

                WsrmFault fault = close
                    ? WsrmUtilities.ValidateCloseSequenceResponse(_session, requestor.MessageId, info,
                                                                  Connection.Last)
                    : WsrmUtilities.ValidateTerminateSequenceResponse(_session, requestor.MessageId, info,
                                                                      Connection.Last);

                if (fault != null)
                {
                    ReliableSession.OnLocalFault(null, fault, null);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                }
            }
            finally
            {
                reply.Close();
            }
        }
 private Message GetReply(Message reply, bool last)
 {
     lock (this.ThisLock)
     {
         if ((reply != null) && (this.replyInfo != null))
         {
             this.replyInfo = null;
         }
         else if ((reply == null) && (this.replyInfo != null))
         {
             reply = this.replyInfo.Message;
         }
         if ((reply == null) && !last)
         {
             return(reply);
         }
         this.replied = true;
     }
     return(reply);
 }
 private Message GetReply(Message reply, bool last)
 {
     lock (this.ThisLock)
     {
         if ((reply != null) && (this.replyInfo != null))
         {
             this.replyInfo = null;
         }
         else if ((reply == null) && (this.replyInfo != null))
         {
             reply = this.replyInfo.Message;
         }
         if ((reply == null) && !last)
         {
             return reply;
         }
         this.replied = true;
     }
     return reply;
 }
        protected override WsrmFault VerifyDuplexProtocolElements(WsrmMessageInfo info)
        {
            WsrmFault fault = base.VerifyDuplexProtocolElements(info);

            if (fault != null)
            {
                return(fault);
            }
            else if (info.CreateSequenceInfo != null && info.CreateSequenceInfo.OfferIdentifier != this.OutputID)
            {
                return(SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedCSOfferId), SR.GetString(SR.UnexpectedCSOfferId)));
            }
            else if (info.CreateSequenceResponseInfo != null)
            {
                return(SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedCSR), SR.GetString(SR.UnexpectedCSR)));
            }
            else
            {
                return(null);
            }
        }
 public static void ValidateCreateSequenceHeaders(MessageVersion messageVersion, ISecureConversationSession securitySession, WsrmMessageInfo info)
 {
     string reason = null;
     if (info.UsesSequenceSSLInfo != null)
     {
         reason = System.ServiceModel.SR.GetString("CSRefusedSSLNotSupported");
     }
     else if ((info.UsesSequenceSTRInfo != null) && (securitySession == null))
     {
         reason = System.ServiceModel.SR.GetString("CSRefusedSTRNoWSSecurity");
     }
     else if ((info.UsesSequenceSTRInfo == null) && (securitySession != null))
     {
         reason = System.ServiceModel.SR.GetString("CSRefusedNoSTRWSSecurity");
     }
     if (reason != null)
     {
         Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, ReliableMessagingVersion.WSReliableMessaging11, reason);
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
     }
 }
Exemple #28
0
        protected TReliableChannel ProcessCreateSequence(WsrmMessageInfo info, TInnerChannel channel, out bool dispatch, out bool newChannel)
        {
            EndpointAddress address;

            dispatch   = false;
            newChannel = false;
            CreateSequenceInfo createSequenceInfo = info.CreateSequenceInfo;

            if (!WsrmUtilities.ValidateCreateSequence <TChannel>(info, this, channel, out address))
            {
                return(default(TReliableChannel));
            }
            lock (base.ThisLock)
            {
                TReliableChannel local = default(TReliableChannel);
                if (((createSequenceInfo.OfferIdentifier == null) || !this.Duplex) || !this.channelsByOutput.TryGetValue(createSequenceInfo.OfferIdentifier, out local))
                {
                    if (!base.IsAccepting)
                    {
                        info.FaultReply = WsrmUtilities.CreateEndpointNotFoundFault(base.MessageVersion, System.ServiceModel.SR.GetString("RMEndpointNotFoundReason", new object[] { this.Uri }));
                        return(default(TReliableChannel));
                    }
                    if (this.inputQueueChannelAcceptor.PendingCount >= base.MaxPendingChannels)
                    {
                        info.FaultReply = WsrmUtilities.CreateCSRefusedServerTooBusyFault(base.MessageVersion, base.ReliableMessagingVersion, System.ServiceModel.SR.GetString("ServerTooBusy", new object[] { this.Uri }));
                        return(default(TReliableChannel));
                    }
                    UniqueId id = WsrmUtilities.NextSequenceId();
                    local = this.CreateChannel(id, createSequenceInfo, this.CreateBinder(channel, address, createSequenceInfo.ReplyTo));
                    this.channelsByInput.Add(id, local);
                    if (this.Duplex)
                    {
                        this.channelsByOutput.Add(createSequenceInfo.OfferIdentifier, local);
                    }
                    dispatch   = this.EnqueueWithoutDispatch((TChannel)local);
                    newChannel = true;
                }
                return(local);
            }
        }
        public static void ValidateCreateSequenceHeaders(MessageVersion messageVersion, ISecureConversationSession securitySession, WsrmMessageInfo info)
        {
            string reason = null;

            if (info.UsesSequenceSSLInfo != null)
            {
                reason = System.ServiceModel.SR.GetString("CSRefusedSSLNotSupported");
            }
            else if ((info.UsesSequenceSTRInfo != null) && (securitySession == null))
            {
                reason = System.ServiceModel.SR.GetString("CSRefusedSTRNoWSSecurity");
            }
            else if ((info.UsesSequenceSTRInfo == null) && (securitySession != null))
            {
                reason = System.ServiceModel.SR.GetString("CSRefusedNoSTRWSSecurity");
            }
            if (reason != null)
            {
                Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, ReliableMessagingVersion.WSReliableMessaging11, reason);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
            }
        }
 internal static UniqueId GetInputId(WsrmMessageInfo info)
 {
     if (info.TerminateSequenceInfo != null)
     {
         return(info.TerminateSequenceInfo.Identifier);
     }
     if (info.SequencedMessageInfo != null)
     {
         return(info.SequencedMessageInfo.SequenceID);
     }
     if (info.AckRequestedInfo != null)
     {
         return(info.AckRequestedInfo.SequenceID);
     }
     if ((info.WsrmHeaderFault != null) && info.WsrmHeaderFault.FaultsInput)
     {
         return(info.WsrmHeaderFault.SequenceID);
     }
     if (info.CloseSequenceInfo != null)
     {
         return(info.CloseSequenceInfo.Identifier);
     }
     return(null);
 }
        public bool VerifySimplexProtocolElements(WsrmMessageInfo info, RequestContext context, bool throwException)
        {
            WsrmFault fault = this.VerifySimplexProtocolElements(info);

            if (fault == null)
            {
                return true;
            }

            info.Message.Close();

            if (throwException)
            {
                Exception e = fault.CreateException();
                this.OnLocalFault(null, fault, context);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e);
            }
            else
            {
                this.OnLocalFault(fault.CreateException(), fault, context);
                return false;
            }
        }
        public bool ProcessInfo(WsrmMessageInfo info, RequestContext context, bool throwException)
        {
            Exception e;
            if (info.ParsingException != null)
            {
                WsrmFault fault;

                if (this.SequenceID != null)
                {
                    string reason = SR.GetString(SR.CouldNotParseWithAction, info.Action);
                    fault = SequenceTerminatedFault.CreateProtocolFault(this.SequenceID, reason, null);
                }
                else
                {
                    fault = null;
                }

                e = new ProtocolException(SR.GetString(SR.MessageExceptionOccurred), info.ParsingException);
                this.OnLocalFault(throwException ? null : e, fault, context);
            }
            else if (info.FaultReply != null)
            {
                e = info.FaultException;
                this.OnLocalFault(throwException ? null : e, info.FaultReply, context);
            }
            else if ((info.WsrmHeaderFault != null) && (info.WsrmHeaderFault.SequenceID != this.InputID)
                && (info.WsrmHeaderFault.SequenceID != this.OutputID))
            {
                e = new ProtocolException(SR.GetString(SR.WrongIdentifierFault, FaultException.GetSafeReasonText(info.WsrmHeaderFault.Reason)));
                this.OnLocalFault(throwException ? null : e, (Message)null, context);
            }
            else if (info.FaultInfo != null)
            {
                if (this.isSessionClosed)
                {
                    UnknownSequenceFault unknownSequenceFault = info.FaultInfo as UnknownSequenceFault;

                    if (unknownSequenceFault != null)
                    {
                        UniqueId sequenceId = unknownSequenceFault.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;
                            }
                            else if (this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
                            {
                                return true;
                            }
                            else
                            {
                                throw Fx.AssertAndThrow("Unknown version.");
                            }
                        }
                    }
                }

                e = info.FaultException;
                if (context != null)
                    context.Close();
                this.OnRemoteFault(throwException ? null : e);
            }
            else
            {
                return true;
            }

            info.Message.Close();
            if (throwException)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(e);
            else
                return false;
        }
 public bool VerifySimplexProtocolElements(WsrmMessageInfo info, RequestContext context)
 {
     return this.VerifySimplexProtocolElements(info, context, false);
 }
 protected virtual WsrmFault VerifyDuplexProtocolElements(WsrmMessageInfo info)
 {
     if ((info.AcknowledgementInfo != null) && (info.AcknowledgementInfo.SequenceID != this.OutputID))
     {
         return new UnknownSequenceFault(info.AcknowledgementInfo.SequenceID);
     }
     if ((info.AckRequestedInfo != null) && (info.AckRequestedInfo.SequenceID != this.InputID))
     {
         return new UnknownSequenceFault(info.AckRequestedInfo.SequenceID);
     }
     if ((info.SequencedMessageInfo != null) && (info.SequencedMessageInfo.SequenceID != this.InputID))
     {
         return new UnknownSequenceFault(info.SequencedMessageInfo.SequenceID);
     }
     if ((info.TerminateSequenceInfo != null) && (info.TerminateSequenceInfo.Identifier != this.InputID))
     {
         if (this.Settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
         {
             return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedTerminateSequence"), System.ServiceModel.SR.GetString("UnexpectedTerminateSequence"));
         }
         if (info.TerminateSequenceInfo.Identifier == this.OutputID)
         {
             return null;
         }
         return new UnknownSequenceFault(info.TerminateSequenceInfo.Identifier);
     }
     if (info.TerminateSequenceResponseInfo != null)
     {
         WsrmUtilities.AssertWsrm11(this.settings.ReliableMessagingVersion);
         if (info.TerminateSequenceResponseInfo.Identifier == this.OutputID)
         {
             return null;
         }
         return new UnknownSequenceFault(info.TerminateSequenceResponseInfo.Identifier);
     }
     if (info.CloseSequenceInfo != null)
     {
         WsrmUtilities.AssertWsrm11(this.settings.ReliableMessagingVersion);
         if (info.CloseSequenceInfo.Identifier == this.InputID)
         {
             return null;
         }
         if (info.CloseSequenceInfo.Identifier == this.OutputID)
         {
             return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnsupportedClose"), System.ServiceModel.SR.GetString("UnsupportedCloseExceptionString"));
         }
         return new UnknownSequenceFault(info.CloseSequenceInfo.Identifier);
     }
     if (info.CloseSequenceResponseInfo == null)
     {
         return null;
     }
     WsrmUtilities.AssertWsrm11(this.settings.ReliableMessagingVersion);
     if (info.CloseSequenceResponseInfo.Identifier == this.OutputID)
     {
         return null;
     }
     if (info.CloseSequenceResponseInfo.Identifier == this.InputID)
     {
         return SequenceTerminatedFault.CreateProtocolFault(this.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedUnexpectedCloseSequenceResponse"), System.ServiceModel.SR.GetString("UnexpectedCloseSequenceResponse"));
     }
     return new UnknownSequenceFault(info.CloseSequenceResponseInfo.Identifier);
 }
 // returns true if the info does not fault the session.
 public bool ProcessInfo(WsrmMessageInfo info, RequestContext context)
 {
     return this.ProcessInfo(info, context, false);
 }
        protected override WsrmFault VerifySimplexProtocolElements(WsrmMessageInfo info)
        {
            if (info.AcknowledgementInfo != null && info.AcknowledgementInfo.SequenceID != this.OutputID)
                return new UnknownSequenceFault(info.AcknowledgementInfo.SequenceID);
            else if (info.AckRequestedInfo != null)
                return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedAckRequested), SR.GetString(SR.UnexpectedAckRequested));
            else if (info.CreateSequenceInfo != null)
                return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedCS), SR.GetString(SR.UnexpectedCS));
            else if (info.SequencedMessageInfo != null)
                return new UnknownSequenceFault(info.SequencedMessageInfo.SequenceID);
            else if (info.TerminateSequenceInfo != null)
            {
                if (this.Settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
                    return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedTerminateSequence), SR.GetString(SR.UnexpectedTerminateSequence));
                else if (info.TerminateSequenceInfo.Identifier == this.OutputID)
                    return null;
                else
                    return new UnknownSequenceFault(info.TerminateSequenceInfo.Identifier);
            }
            else if (info.TerminateSequenceResponseInfo != null)
            {
                WsrmUtilities.AssertWsrm11(this.Settings.ReliableMessagingVersion);

                if (info.TerminateSequenceResponseInfo.Identifier == this.OutputID)
                    return null;
                else
                    return new UnknownSequenceFault(info.TerminateSequenceResponseInfo.Identifier);
            }
            else if (info.CloseSequenceInfo != null)
            {
                WsrmUtilities.AssertWsrm11(this.Settings.ReliableMessagingVersion);

                if (info.CloseSequenceInfo.Identifier == this.OutputID)
                    return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnsupportedClose), SR.GetString(SR.UnsupportedCloseExceptionString));
                else
                    return new UnknownSequenceFault(info.CloseSequenceInfo.Identifier);
            }
            else if (info.CloseSequenceResponseInfo != null)
            {
                WsrmUtilities.AssertWsrm11(this.Settings.ReliableMessagingVersion);

                if (info.CloseSequenceResponseInfo.Identifier == this.OutputID)
                    return null;
                else
                    return new UnknownSequenceFault(info.CloseSequenceResponseInfo.Identifier);
            }
            else
                return null;
        }
        void ProcessReply(Message reply, IReliableRequest request, Int64 requestSequenceNumber)
        {
            WsrmMessageInfo messageInfo = WsrmMessageInfo.Get(this.settings.MessageVersion,
                                                              this.settings.ReliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(), reply);

            if (!this.session.ProcessInfo(messageInfo, null))
            {
                return;
            }

            if (!this.session.VerifyDuplexProtocolElements(messageInfo, null))
            {
                return;
            }

            bool wsrm11 = this.settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;

            if (messageInfo.WsrmHeaderFault != null)
            {
                // Close message now, going to stop processing in all cases.
                messageInfo.Message.Close();

                if (!(messageInfo.WsrmHeaderFault is UnknownSequenceFault))
                {
                    throw Fx.AssertAndThrow("Fault must be UnknownSequence fault.");
                }

                if (this.terminateRequestor == null)
                {
                    throw Fx.AssertAndThrow("If we start getting UnknownSequence, terminateRequestor cannot be null.");
                }

                this.terminateRequestor.SetInfo(messageInfo);

                return;
            }

            if (messageInfo.AcknowledgementInfo == null)
            {
                WsrmFault fault = SequenceTerminatedFault.CreateProtocolFault(this.session.InputID,
                                                                              SR.GetString(SR.SequenceTerminatedReplyMissingAcknowledgement),
                                                                              SR.GetString(SR.ReplyMissingAcknowledgement));
                messageInfo.Message.Close();
                this.session.OnLocalFault(fault.CreateException(), fault, null);
                return;
            }

            if (wsrm11 && (messageInfo.TerminateSequenceInfo != null))
            {
                UniqueId faultId = (messageInfo.TerminateSequenceInfo.Identifier == this.session.OutputID)
                    ? this.session.InputID
                    : this.session.OutputID;

                WsrmFault fault = SequenceTerminatedFault.CreateProtocolFault(faultId,
                                                                              SR.GetString(SR.SequenceTerminatedUnsupportedTerminateSequence),
                                                                              SR.GetString(SR.UnsupportedTerminateSequenceExceptionString));
                messageInfo.Message.Close();
                this.session.OnLocalFault(fault.CreateException(), fault, null);
                return;
            }
            else if (wsrm11 && messageInfo.AcknowledgementInfo.Final)
            {
                // Close message now, going to stop processing in all cases.
                messageInfo.Message.Close();

                if (this.closeRequestor == null)
                {
                    // Remote endpoint signaled Close, this is not allowed so we fault.
                    string exceptionString = SR.GetString(SR.UnsupportedCloseExceptionString);
                    string faultString     = SR.GetString(SR.SequenceTerminatedUnsupportedClose);

                    WsrmFault fault = SequenceTerminatedFault.CreateProtocolFault(this.session.OutputID, faultString,
                                                                                  exceptionString);
                    this.session.OnLocalFault(fault.CreateException(), fault, null);
                }
                else
                {
                    WsrmFault fault = WsrmUtilities.ValidateFinalAck(this.session, messageInfo, this.connection.Last);

                    if (fault == null)
                    {
                        // Received valid final ack after sending Close, inform the close thread.
                        this.closeRequestor.SetInfo(messageInfo);
                    }
                    else
                    {
                        // Received invalid final ack after sending Close, fault.
                        this.session.OnLocalFault(fault.CreateException(), fault, null);
                    }
                }

                return;
            }

            int bufferRemaining = -1;

            if (this.settings.FlowControlEnabled)
            {
                bufferRemaining = messageInfo.AcknowledgementInfo.BufferRemaining;
            }

            // We accept no more than MaxSequenceRanges ranges to limit the serialized ack size and
            // the amount of memory taken up by the ack ranges. Since request reply uses the presence of
            // a reply as an acknowledgement we cannot call ProcessTransferred (which stops retrying the
            // request) if we intend to drop the message. This means the limit is not strict since we do
            // not check for the limit and merge the ranges atomically. The limit + the number of
            // concurrent threads is a sufficient mitigation.
            if ((messageInfo.SequencedMessageInfo != null) &&
                !ReliableInputConnection.CanMerge(messageInfo.SequencedMessageInfo.SequenceNumber, this.ranges))
            {
                messageInfo.Message.Close();
                return;
            }

            bool exitGuard = this.replyAckConsistencyGuard != null?this.replyAckConsistencyGuard.Enter() : false;

            try
            {
                this.connection.ProcessTransferred(requestSequenceNumber,
                                                   messageInfo.AcknowledgementInfo.Ranges, bufferRemaining);

                this.session.OnRemoteActivity(this.connection.Strategy.QuotaRemaining == 0);

                if (messageInfo.SequencedMessageInfo != null)
                {
                    lock (this.ThisLock)
                    {
                        this.ranges = this.ranges.MergeWith(messageInfo.SequencedMessageInfo.SequenceNumber);
                    }
                }
            }
            finally
            {
                if (exitGuard)
                {
                    this.replyAckConsistencyGuard.Exit();
                }
            }

            if (request != null)
            {
                if (WsrmUtilities.IsWsrmAction(this.settings.ReliableMessagingVersion, messageInfo.Action))
                {
                    messageInfo.Message.Close();
                    request.Set(null);
                }
                else
                {
                    request.Set(messageInfo.Message);
                }
            }

            // The termination mechanism in the TerminateSequence fails with RequestReply.
            // Since the ack ranges are updated after ProcessTransferred is called and
            // ProcessTransferred potentially signals the Termination process, this channel
            // winds up sending a message with the ack for last message missing.
            // Thus we send the termination after we update the ranges.

            if ((this.shutdownHandle != null) && this.connection.CheckForTermination())
            {
                this.shutdownHandle.Set();
            }

            if (request != null)
            {
                request.Complete();
            }
        }
        public static WsrmMessageInfo Get(MessageVersion messageVersion,
            ReliableMessagingVersion reliableMessagingVersion, IChannel channel, ISession session, Message message,
            bool csrOnly)
        {
            WsrmMessageInfo messageInfo = new WsrmMessageInfo();
            messageInfo.message = message;
            bool isFault = true;

            try
            {
                isFault = message.IsFault;
                MessageHeaders headers = message.Headers;
                string action = headers.Action;
                messageInfo.action = action;
                bool foundAction = false;
                bool wsrmFeb2005 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005;
                bool wsrm11 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;
                bool csOnly = false;

                if (action == WsrmIndex.GetCreateSequenceResponseActionString(reliableMessagingVersion))
                {
                    messageInfo.createSequenceResponseInfo = CreateSequenceResponseInfo.ReadMessage(messageVersion,
                        reliableMessagingVersion, message, headers);
                    ValidateMustUnderstand(messageVersion, message);
                    return messageInfo;
                }

                if (csrOnly)
                    return messageInfo;

                if (action == WsrmIndex.GetTerminateSequenceActionString(reliableMessagingVersion))
                {
                    messageInfo.terminateSequenceInfo = TerminateSequenceInfo.ReadMessage(messageVersion,
                        reliableMessagingVersion, message, headers);
                    foundAction = true;
                }
                else if (action == WsrmIndex.GetCreateSequenceActionString(reliableMessagingVersion))
                {
                    messageInfo.createSequenceInfo = CreateSequenceInfo.ReadMessage(messageVersion,
                        reliableMessagingVersion, session as ISecureConversationSession, message, headers);

                    if (wsrmFeb2005)
                    {
                        ValidateMustUnderstand(messageVersion, message);
                        return messageInfo;
                    }

                    csOnly = true;
                }
                else if (wsrm11)
                {
                    if (action == Wsrm11Strings.CloseSequenceAction)
                    {
                        messageInfo.closeSequenceInfo = CloseSequenceInfo.ReadMessage(messageVersion, message,
                            headers);
                        foundAction = true;
                    }
                    else if (action == Wsrm11Strings.CloseSequenceResponseAction)
                    {
                        messageInfo.closeSequenceResponseInfo = CloseSequenceResponseInfo.ReadMessage(messageVersion,
                             message, headers);
                        foundAction = true;
                    }
                    else if (action == WsrmIndex.GetTerminateSequenceResponseActionString(reliableMessagingVersion))
                    {
                        messageInfo.terminateSequenceResponseInfo = TerminateSequenceResponseInfo.ReadMessage(messageVersion,
                             message, headers);
                        foundAction = true;
                    }
                }

                string wsrmNs = WsrmIndex.GetNamespaceString(reliableMessagingVersion);
                bool soap11 = messageVersion.Envelope == EnvelopeVersion.Soap11;
                bool foundHeader = false;
                int foundTooManyIndex = -1;
                int sequenceIndex = -1;
                int ackIndex = -1;
                int ackRequestedIndex = -1;
                int maxIndex = -1;
                int minIndex = -1;
                int sequenceFaultIndex = -1;
                int usesSequenceSSLIndex = -1;
                int usesSequenceSTRIndex = -1;

                for (int index = 0; index < headers.Count; index++)
                {
                    MessageHeaderInfo header = headers[index];

                    if (!messageVersion.Envelope.IsUltimateDestinationActor(header.Actor))
                        continue;

                    if (header.Namespace == wsrmNs)
                    {
                        bool setIndex = true;

                        if (csOnly)
                        {
                            if (wsrm11 && (header.Name == Wsrm11Strings.UsesSequenceSSL))
                            {
                                if (usesSequenceSSLIndex != -1)
                                {
                                    foundTooManyIndex = index;
                                    break;
                                }
                                usesSequenceSSLIndex = index;
                            }
                            else if (wsrm11 && (header.Name == Wsrm11Strings.UsesSequenceSTR))
                            {
                                if (usesSequenceSTRIndex != -1)
                                {
                                    foundTooManyIndex = index;
                                    break;
                                }
                                usesSequenceSTRIndex = index;
                            }
                            else
                            {
                                setIndex = false;
                            }
                        }
                        else
                        {
                            if (header.Name == WsrmFeb2005Strings.Sequence)
                            {
                                if (sequenceIndex != -1)
                                {
                                    foundTooManyIndex = index;
                                    break;
                                }
                                sequenceIndex = index;
                            }
                            else if (header.Name == WsrmFeb2005Strings.SequenceAcknowledgement)
                            {
                                if (ackIndex != -1)
                                {
                                    foundTooManyIndex = index;
                                    break;
                                }
                                ackIndex = index;
                            }
                            else if (header.Name == WsrmFeb2005Strings.AckRequested)
                            {
                                if (ackRequestedIndex != -1)
                                {
                                    foundTooManyIndex = index;
                                    break;
                                }
                                ackRequestedIndex = index;
                            }
                            else if (soap11 && (header.Name == WsrmFeb2005Strings.SequenceFault))
                            {
                                if (sequenceFaultIndex != -1)
                                {
                                    foundTooManyIndex = index;
                                    break;
                                }
                                sequenceFaultIndex = index;
                            }
                            else
                            {
                                setIndex = false;
                            }
                        }

                        if (setIndex)
                        {
                            if (index > maxIndex)
                                maxIndex = index;

                            if (minIndex == -1)
                                minIndex = index;
                        }
                    }
                }

                if (foundTooManyIndex != -1)
                {
                    Collection<MessageHeaderInfo> notUnderstoodHeaders = new Collection<MessageHeaderInfo>();
                    notUnderstoodHeaders.Add(headers[foundTooManyIndex]);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new MustUnderstandSoapException(notUnderstoodHeaders, messageVersion.Envelope));
                }

                if (maxIndex > -1)
                {
                    BufferedMessage bufferedMessage = message as BufferedMessage;

                    if (bufferedMessage != null && bufferedMessage.Headers.ContainsOnlyBufferedMessageHeaders)
                    {
                        foundHeader = true;

                        using (XmlDictionaryReader reader = headers.GetReaderAtHeader(minIndex))
                        {
                            for (int index = minIndex; index <= maxIndex; index++)
                            {
                                MessageHeaderInfo header = headers[index];

                                if (csOnly)
                                {
                                    if (wsrm11 && (index == usesSequenceSSLIndex))
                                    {
                                        messageInfo.usesSequenceSSLInfo = WsrmUsesSequenceSSLInfo.ReadHeader(
                                            reader, header);
                                        headers.UnderstoodHeaders.Add(header);
                                    }
                                    else if (wsrm11 && (index == usesSequenceSTRIndex))
                                    {
                                        messageInfo.usesSequenceSTRInfo = WsrmUsesSequenceSTRInfo.ReadHeader(
                                            reader, header);
                                        headers.UnderstoodHeaders.Add(header);
                                    }
                                    else
                                    {
                                        reader.Skip();
                                    }
                                }
                                else
                                {
                                    if (index == sequenceIndex)
                                    {
                                        messageInfo.sequencedMessageInfo = WsrmSequencedMessageInfo.ReadHeader(
                                            reliableMessagingVersion, reader, header);
                                        headers.UnderstoodHeaders.Add(header);
                                    }
                                    else if (index == ackIndex)
                                    {
                                        messageInfo.acknowledgementInfo = WsrmAcknowledgmentInfo.ReadHeader(
                                            reliableMessagingVersion, reader, header);
                                        headers.UnderstoodHeaders.Add(header);
                                    }
                                    else if (index == ackRequestedIndex)
                                    {
                                        messageInfo.ackRequestedInfo = WsrmAckRequestedInfo.ReadHeader(
                                            reliableMessagingVersion, reader, header);
                                        headers.UnderstoodHeaders.Add(header);
                                    }
                                    else
                                    {
                                        reader.Skip();
                                    }
                                }
                            }
                        }
                    }
                }

                if (maxIndex > -1 && !foundHeader)
                {
                    foundHeader = true;

                    if (csOnly)
                    {
                        if (usesSequenceSSLIndex != -1)
                        {
                            using (XmlDictionaryReader reader = headers.GetReaderAtHeader(usesSequenceSSLIndex))
                            {
                                MessageHeaderInfo header = headers[usesSequenceSSLIndex];
                                messageInfo.usesSequenceSSLInfo = WsrmUsesSequenceSSLInfo.ReadHeader(
                                    reader, header);
                                headers.UnderstoodHeaders.Add(header);
                            }
                        }

                        if (usesSequenceSTRIndex != -1)
                        {
                            using (XmlDictionaryReader reader = headers.GetReaderAtHeader(usesSequenceSTRIndex))
                            {
                                MessageHeaderInfo header = headers[usesSequenceSTRIndex];
                                messageInfo.usesSequenceSTRInfo = WsrmUsesSequenceSTRInfo.ReadHeader(
                                    reader, header);
                                headers.UnderstoodHeaders.Add(header);
                            }
                        }
                    }
                    else
                    {
                        if (sequenceIndex != -1)
                        {
                            using (XmlDictionaryReader reader = headers.GetReaderAtHeader(sequenceIndex))
                            {
                                MessageHeaderInfo header = headers[sequenceIndex];

                                messageInfo.sequencedMessageInfo = WsrmSequencedMessageInfo.ReadHeader(
                                    reliableMessagingVersion, reader, header);
                                headers.UnderstoodHeaders.Add(header);
                            }
                        }

                        if (ackIndex != -1)
                        {
                            using (XmlDictionaryReader reader = headers.GetReaderAtHeader(ackIndex))
                            {
                                MessageHeaderInfo header = headers[ackIndex];
                                messageInfo.acknowledgementInfo = WsrmAcknowledgmentInfo.ReadHeader(
                                    reliableMessagingVersion, reader, header);
                                headers.UnderstoodHeaders.Add(header);
                            }
                        }

                        if (ackRequestedIndex != -1)
                        {
                            using (XmlDictionaryReader reader = headers.GetReaderAtHeader(ackRequestedIndex))
                            {
                                MessageHeaderInfo header = headers[ackRequestedIndex];
                                messageInfo.ackRequestedInfo = WsrmAckRequestedInfo.ReadHeader(reliableMessagingVersion,
                                    reader, header);
                                headers.UnderstoodHeaders.Add(header);
                            }
                        }
                    }
                }

                if (csOnly)
                {
                    CreateSequenceInfo.ValidateCreateSequenceHeaders(messageVersion,
                        session as ISecureConversationSession, messageInfo);
                    ValidateMustUnderstand(messageVersion, message);
                    return messageInfo;
                }

                if (messageInfo.sequencedMessageInfo == null && messageInfo.action == null)
                {
                    if (wsrmFeb2005)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageHeaderException(SR.GetString(SR.NoActionNoSequenceHeaderReason), messageVersion.Addressing.Namespace, AddressingStrings.Action, false));
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            CreateWsrmRequiredException(messageVersion));
                    }
                }

                if (messageInfo.sequencedMessageInfo == null && message.IsFault)
                {
                    messageInfo.faultInfo = MessageFault.CreateFault(message, TransportDefaults.MaxRMFaultSize);
                    WsrmHeaderFault wsrmFault;

                    if (soap11)
                    {
                        if (WsrmHeaderFault.TryCreateFault11(reliableMessagingVersion, message, messageInfo.faultInfo, sequenceFaultIndex, out wsrmFault))
                        {
                            messageInfo.faultInfo = wsrmFault;
                            messageInfo.faultException = WsrmHeaderFault.CreateException(wsrmFault);
                        }
                    }
                    else
                    {
                        if (WsrmHeaderFault.TryCreateFault12(reliableMessagingVersion, message, messageInfo.faultInfo, out wsrmFault))
                        {
                            messageInfo.faultInfo = wsrmFault;
                            messageInfo.faultException = WsrmHeaderFault.CreateException(wsrmFault);
                        }
                    }

                    // Not a wsrm fault, maybe it is another fault we should understand (i.e. addressing or soap fault).
                    if (wsrmFault == null)
                    {
                        FaultConverter faultConverter = channel.GetProperty<FaultConverter>();

                        if (faultConverter == null)
                        {
                            faultConverter = FaultConverter.GetDefaultFaultConverter(messageVersion);
                        }

                        if (!faultConverter.TryCreateException(message, messageInfo.faultInfo, out messageInfo.faultException))
                        {
                            messageInfo.faultException = new ProtocolException(SR.GetString(SR.UnrecognizedFaultReceived, messageInfo.faultInfo.Code.Namespace, messageInfo.faultInfo.Code.Name, System.ServiceModel.FaultException.GetSafeReasonText(messageInfo.faultInfo)));
                        }
                    }

                    foundAction = true;
                }

                if (!foundHeader && !foundAction)
                {
                    if (wsrmFeb2005)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            new ActionNotSupportedException(SR.GetString(SR.NonWsrmFeb2005ActionNotSupported, action)));
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            CreateWsrmRequiredException(messageVersion));
                    }
                }

                if (foundAction || WsrmUtilities.IsWsrmAction(reliableMessagingVersion, action))
                {
                    ValidateMustUnderstand(messageVersion, message);
                }
            }
            catch (InternalFaultException exception)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);

                messageInfo.FaultReply = exception.FaultReply;
                messageInfo.faultException = exception.InnerException;
            }
            catch (CommunicationException exception)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);

                if (isFault)
                {
                    messageInfo.parsingException = exception;
                    return messageInfo;
                }

                FaultConverter faultConverter = channel.GetProperty<FaultConverter>();
                if (faultConverter == null)
                    faultConverter = FaultConverter.GetDefaultFaultConverter(messageVersion);

                if (faultConverter.TryCreateFaultMessage(exception, out messageInfo.faultReply))
                {
                    messageInfo.faultException = new ProtocolException(SR.GetString(SR.MessageExceptionOccurred), exception);
                }
                else
                {
                    messageInfo.parsingException = new ProtocolException(SR.GetString(SR.MessageExceptionOccurred), exception);
                }
            }
            catch (XmlException exception)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                    DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);

                messageInfo.parsingException = new ProtocolException(SR.GetString(SR.MessageExceptionOccurred), exception);
            }

            return messageInfo;
        }
 public static WsrmMessageInfo Get(MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, IChannel channel, ISession session, System.ServiceModel.Channels.Message message, bool csrOnly)
 {
     WsrmMessageInfo info = new WsrmMessageInfo {
         message = message
     };
     bool isFault = true;
     try
     {
         isFault = message.IsFault;
         MessageHeaders headers = message.Headers;
         string action = headers.Action;
         info.action = action;
         bool flag2 = false;
         bool flag3 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005;
         bool flag4 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;
         bool flag5 = false;
         if (action == WsrmIndex.GetCreateSequenceResponseActionString(reliableMessagingVersion))
         {
             info.createSequenceResponseInfo = System.ServiceModel.Channels.CreateSequenceResponseInfo.ReadMessage(messageVersion, reliableMessagingVersion, message, headers);
             ValidateMustUnderstand(messageVersion, message);
             return info;
         }
         if (csrOnly)
         {
             return info;
         }
         if (action == WsrmIndex.GetTerminateSequenceActionString(reliableMessagingVersion))
         {
             info.terminateSequenceInfo = System.ServiceModel.Channels.TerminateSequenceInfo.ReadMessage(messageVersion, reliableMessagingVersion, message, headers);
             flag2 = true;
         }
         else if (action == WsrmIndex.GetCreateSequenceActionString(reliableMessagingVersion))
         {
             info.createSequenceInfo = System.ServiceModel.Channels.CreateSequenceInfo.ReadMessage(messageVersion, reliableMessagingVersion, session as ISecureConversationSession, message, headers);
             if (flag3)
             {
                 ValidateMustUnderstand(messageVersion, message);
                 return info;
             }
             flag5 = true;
         }
         else if (flag4)
         {
             if (action == "http://docs.oasis-open.org/ws-rx/wsrm/200702/CloseSequence")
             {
                 info.closeSequenceInfo = System.ServiceModel.Channels.CloseSequenceInfo.ReadMessage(messageVersion, message, headers);
                 flag2 = true;
             }
             else if (action == "http://docs.oasis-open.org/ws-rx/wsrm/200702/CloseSequenceResponse")
             {
                 info.closeSequenceResponseInfo = System.ServiceModel.Channels.CloseSequenceResponseInfo.ReadMessage(messageVersion, message, headers);
                 flag2 = true;
             }
             else if (action == WsrmIndex.GetTerminateSequenceResponseActionString(reliableMessagingVersion))
             {
                 info.terminateSequenceResponseInfo = System.ServiceModel.Channels.TerminateSequenceResponseInfo.ReadMessage(messageVersion, message, headers);
                 flag2 = true;
             }
         }
         string namespaceString = WsrmIndex.GetNamespaceString(reliableMessagingVersion);
         bool flag6 = messageVersion.Envelope == EnvelopeVersion.Soap11;
         bool flag7 = false;
         int num = -1;
         int headerIndex = -1;
         int num3 = -1;
         int num4 = -1;
         int num5 = -1;
         int num6 = -1;
         int index = -1;
         int num8 = -1;
         int num9 = -1;
         for (int i = 0; i < headers.Count; i++)
         {
             MessageHeaderInfo info2 = headers[i];
             if (messageVersion.Envelope.IsUltimateDestinationActor(info2.Actor) && (info2.Namespace == namespaceString))
             {
                 bool flag8 = true;
                 if (flag5)
                 {
                     if (flag4 && (info2.Name == "UsesSequenceSSL"))
                     {
                         if (num8 != -1)
                         {
                             num = i;
                             break;
                         }
                         num8 = i;
                     }
                     else if (flag4 && (info2.Name == "UsesSequenceSTR"))
                     {
                         if (num9 != -1)
                         {
                             num = i;
                             break;
                         }
                         num9 = i;
                     }
                     else
                     {
                         flag8 = false;
                     }
                 }
                 else if (info2.Name == "Sequence")
                 {
                     if (headerIndex != -1)
                     {
                         num = i;
                         break;
                     }
                     headerIndex = i;
                 }
                 else if (info2.Name == "SequenceAcknowledgement")
                 {
                     if (num3 != -1)
                     {
                         num = i;
                         break;
                     }
                     num3 = i;
                 }
                 else if (info2.Name == "AckRequested")
                 {
                     if (num4 != -1)
                     {
                         num = i;
                         break;
                     }
                     num4 = i;
                 }
                 else if (flag6 && (info2.Name == "SequenceFault"))
                 {
                     if (index != -1)
                     {
                         num = i;
                         break;
                     }
                     index = i;
                 }
                 else
                 {
                     flag8 = false;
                 }
                 if (flag8)
                 {
                     if (i > num5)
                     {
                         num5 = i;
                     }
                     if (num6 == -1)
                     {
                         num6 = i;
                     }
                 }
             }
         }
         if (num != -1)
         {
             Collection<MessageHeaderInfo> notUnderstoodHeaders = new Collection<MessageHeaderInfo> {
                 headers[num]
             };
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MustUnderstandSoapException(notUnderstoodHeaders, messageVersion.Envelope));
         }
         if (num5 > -1)
         {
             BufferedMessage message2 = message as BufferedMessage;
             if ((message2 != null) && message2.Headers.ContainsOnlyBufferedMessageHeaders)
             {
                 flag7 = true;
                 using (XmlDictionaryReader reader = headers.GetReaderAtHeader(num6))
                 {
                     for (int j = num6; j <= num5; j++)
                     {
                         MessageHeaderInfo header = headers[j];
                         if (flag5)
                         {
                             if (flag4 && (j == num8))
                             {
                                 info.usesSequenceSSLInfo = WsrmUsesSequenceSSLInfo.ReadHeader(reader, header);
                                 headers.UnderstoodHeaders.Add(header);
                             }
                             else if (flag4 && (j == num9))
                             {
                                 info.usesSequenceSTRInfo = WsrmUsesSequenceSTRInfo.ReadHeader(reader, header);
                                 headers.UnderstoodHeaders.Add(header);
                             }
                             else
                             {
                                 reader.Skip();
                             }
                         }
                         else if (j == headerIndex)
                         {
                             info.sequencedMessageInfo = WsrmSequencedMessageInfo.ReadHeader(reliableMessagingVersion, reader, header);
                             headers.UnderstoodHeaders.Add(header);
                         }
                         else if (j == num3)
                         {
                             info.acknowledgementInfo = WsrmAcknowledgmentInfo.ReadHeader(reliableMessagingVersion, reader, header);
                             headers.UnderstoodHeaders.Add(header);
                         }
                         else if (j == num4)
                         {
                             info.ackRequestedInfo = WsrmAckRequestedInfo.ReadHeader(reliableMessagingVersion, reader, header);
                             headers.UnderstoodHeaders.Add(header);
                         }
                         else
                         {
                             reader.Skip();
                         }
                     }
                 }
             }
         }
         if ((num5 > -1) && !flag7)
         {
             flag7 = true;
             if (flag5)
             {
                 if (num8 != -1)
                 {
                     using (XmlDictionaryReader reader2 = headers.GetReaderAtHeader(num8))
                     {
                         MessageHeaderInfo info4 = headers[num8];
                         info.usesSequenceSSLInfo = WsrmUsesSequenceSSLInfo.ReadHeader(reader2, info4);
                         headers.UnderstoodHeaders.Add(info4);
                     }
                 }
                 if (num9 == -1)
                 {
                     goto Label_05CB;
                 }
                 using (XmlDictionaryReader reader3 = headers.GetReaderAtHeader(num9))
                 {
                     MessageHeaderInfo info5 = headers[num9];
                     info.usesSequenceSTRInfo = WsrmUsesSequenceSTRInfo.ReadHeader(reader3, info5);
                     headers.UnderstoodHeaders.Add(info5);
                     goto Label_05CB;
                 }
             }
             if (headerIndex != -1)
             {
                 using (XmlDictionaryReader reader4 = headers.GetReaderAtHeader(headerIndex))
                 {
                     MessageHeaderInfo info6 = headers[headerIndex];
                     info.sequencedMessageInfo = WsrmSequencedMessageInfo.ReadHeader(reliableMessagingVersion, reader4, info6);
                     headers.UnderstoodHeaders.Add(info6);
                 }
             }
             if (num3 != -1)
             {
                 using (XmlDictionaryReader reader5 = headers.GetReaderAtHeader(num3))
                 {
                     MessageHeaderInfo info7 = headers[num3];
                     info.acknowledgementInfo = WsrmAcknowledgmentInfo.ReadHeader(reliableMessagingVersion, reader5, info7);
                     headers.UnderstoodHeaders.Add(info7);
                 }
             }
             if (num4 != -1)
             {
                 using (XmlDictionaryReader reader6 = headers.GetReaderAtHeader(num4))
                 {
                     MessageHeaderInfo info8 = headers[num4];
                     info.ackRequestedInfo = WsrmAckRequestedInfo.ReadHeader(reliableMessagingVersion, reader6, info8);
                     headers.UnderstoodHeaders.Add(info8);
                 }
             }
         }
     Label_05CB:
         if (flag5)
         {
             System.ServiceModel.Channels.CreateSequenceInfo.ValidateCreateSequenceHeaders(messageVersion, session as ISecureConversationSession, info);
             ValidateMustUnderstand(messageVersion, message);
             return info;
         }
         if ((info.sequencedMessageInfo == null) && (info.action == null))
         {
             if (flag3)
             {
                 throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageHeaderException(System.ServiceModel.SR.GetString("NoActionNoSequenceHeaderReason"), messageVersion.Addressing.Namespace, "Action", false));
             }
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateWsrmRequiredException(messageVersion));
         }
         if ((info.sequencedMessageInfo == null) && message.IsFault)
         {
             System.ServiceModel.Channels.WsrmHeaderFault fault;
             info.faultInfo = System.ServiceModel.Channels.MessageFault.CreateFault(message, 0x10000);
             if (flag6)
             {
                 if (System.ServiceModel.Channels.WsrmHeaderFault.TryCreateFault11(reliableMessagingVersion, message, info.faultInfo, index, out fault))
                 {
                     info.faultInfo = fault;
                     info.faultException = WsrmFault.CreateException(fault);
                 }
             }
             else if (System.ServiceModel.Channels.WsrmHeaderFault.TryCreateFault12(reliableMessagingVersion, message, info.faultInfo, out fault))
             {
                 info.faultInfo = fault;
                 info.faultException = WsrmFault.CreateException(fault);
             }
             if (fault == null)
             {
                 FaultConverter property = channel.GetProperty<FaultConverter>();
                 if (property == null)
                 {
                     property = FaultConverter.GetDefaultFaultConverter(messageVersion);
                 }
                 if (!property.TryCreateException(message, info.faultInfo, out info.faultException))
                 {
                     info.faultException = new ProtocolException(System.ServiceModel.SR.GetString("UnrecognizedFaultReceived", new object[] { info.faultInfo.Code.Namespace, info.faultInfo.Code.Name, System.ServiceModel.FaultException.GetSafeReasonText(info.faultInfo) }));
                 }
             }
             flag2 = true;
         }
         if (!flag7 && !flag2)
         {
             if (flag3)
             {
                 throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ActionNotSupportedException(System.ServiceModel.SR.GetString("NonWsrmFeb2005ActionNotSupported", new object[] { action })));
             }
             throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateWsrmRequiredException(messageVersion));
         }
         if (!flag2 && !WsrmUtilities.IsWsrmAction(reliableMessagingVersion, action))
         {
             return info;
         }
         ValidateMustUnderstand(messageVersion, message);
     }
     catch (InternalFaultException exception)
     {
         if (System.ServiceModel.DiagnosticUtility.ShouldTraceInformation)
         {
             System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
         }
         info.FaultReply = exception.FaultReply;
         info.faultException = exception.InnerException;
     }
     catch (CommunicationException exception2)
     {
         if (System.ServiceModel.DiagnosticUtility.ShouldTraceInformation)
         {
             System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
         }
         if (isFault)
         {
             info.parsingException = exception2;
             return info;
         }
         FaultConverter defaultFaultConverter = channel.GetProperty<FaultConverter>();
         if (defaultFaultConverter == null)
         {
             defaultFaultConverter = FaultConverter.GetDefaultFaultConverter(messageVersion);
         }
         if (defaultFaultConverter.TryCreateFaultMessage(exception2, out info.faultReply))
         {
             info.faultException = new ProtocolException(System.ServiceModel.SR.GetString("MessageExceptionOccurred"), exception2);
             return info;
         }
         info.parsingException = new ProtocolException(System.ServiceModel.SR.GetString("MessageExceptionOccurred"), exception2);
     }
     catch (XmlException exception3)
     {
         if (System.ServiceModel.DiagnosticUtility.ShouldTraceInformation)
         {
             System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information);
         }
         info.parsingException = new ProtocolException(System.ServiceModel.SR.GetString("MessageExceptionOccurred"), exception3);
     }
     return info;
 }
 public override void SetInfo(WsrmMessageInfo info)
 {
     throw Fx.AssertAndThrow("Not Supported.");
 }
 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;
 }
 public void ProcessDemuxedMessage(WsrmMessageInfo info)
 {
     try
     {
         this.ProcessMessage(info);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.ReliableSession.OnUnknownException(exception);
     }
 }
 protected override void ProcessMessage(WsrmMessageInfo info)
 {
     if (base.ReliableSession.ProcessInfo(info, null) && base.ReliableSession.VerifyDuplexProtocolElements(info, null))
     {
         if (info.CreateSequenceInfo == null)
         {
             base.ProcessDuplexMessage(info);
         }
         else
         {
             EndpointAddress address;
             if (WsrmUtilities.ValidateCreateSequence<IDuplexSessionChannel>(info, this.listener, base.Binder.Channel, out address))
             {
                 Message response = WsrmUtilities.CreateCreateSequenceResponse(base.Settings.MessageVersion, base.Settings.ReliableMessagingVersion, true, info.CreateSequenceInfo, base.Settings.Ordered, base.ReliableSession.InputID, address);
                 using (info.Message)
                 {
                     using (response)
                     {
                         if (((IServerReliableChannelBinder) base.Binder).AddressResponse(info.Message, response))
                         {
                             base.Binder.Send(response, base.DefaultSendTimeout);
                         }
                     }
                     return;
                 }
             }
             base.ReliableSession.OnLocalFault(info.FaultException, info.FaultReply, null);
         }
     }
 }
 protected override WsrmFault ProcessRequestorResponse(ReliableRequestor requestor, string requestName, WsrmMessageInfo info)
 {
     if (requestor != null)
     {
         requestor.SetInfo(info);
         return null;
     }
     string faultReason = System.ServiceModel.SR.GetString("ReceivedResponseBeforeRequestFaultString", new object[] { requestName });
     string exceptionMessage = System.ServiceModel.SR.GetString("ReceivedResponseBeforeRequestExceptionString", new object[] { requestName });
     return SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.OutputID, faultReason, exceptionMessage);
 }
 protected abstract WsrmFault VerifySimplexProtocolElements(WsrmMessageInfo info);
 protected abstract WsrmFault ProcessRequestorResponse(ReliableRequestor requestor, string requestName, WsrmMessageInfo info);
        protected override WsrmFault VerifyDuplexProtocolElements(WsrmMessageInfo info)
        {
            WsrmFault fault = base.VerifyDuplexProtocolElements(info);

            if (fault != null)
                return fault;
            else if (info.CreateSequenceInfo != null)
                return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedCS), SR.GetString(SR.UnexpectedCS));
            else if (info.CreateSequenceResponseInfo != null && info.CreateSequenceResponseInfo.Identifier != this.OutputID)
                return SequenceTerminatedFault.CreateProtocolFault(this.OutputID, SR.GetString(SR.SequenceTerminatedUnexpectedCSROfferId), SR.GetString(SR.UnexpectedCSROfferId));
            else
                return null;
        }
 protected override WsrmFault ProcessRequestorResponse(ReliableRequestor requestor, string requestName, WsrmMessageInfo info)
 {
     if (requestor != null)
     {
         requestor.SetInfo(info);
         return(null);
     }
     else
     {
         string faultString     = SR.Format(SR.ReceivedResponseBeforeRequestFaultString, requestName);
         string exceptionString = SR.Format(SR.ReceivedResponseBeforeRequestExceptionString, requestName);
         return(SequenceTerminatedFault.CreateProtocolFault(ReliableSession.OutputID, faultString, exceptionString));
     }
 }
        void ProcessCloseOrTerminateReply(bool close, Message reply)
        {
            if (reply == null)
            {
                // In the close case, the requestor is configured to throw TimeoutException instead of returning null.
                // In the terminate case, this value can be null, but the caller should not call this method.
                throw Fx.AssertAndThrow("Argument reply cannot be null.");
            }

            ReliableMessagingVersion reliableMessagingVersion = this.settings.ReliableMessagingVersion;

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
            {
                if (close)
                {
                    throw Fx.AssertAndThrow("Close does not exist in Feb2005.");
                }

                reply.Close();
            }
            else if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                WsrmMessageInfo info = this.closeRequestor.GetInfo();

                // Close - Final ack made it.
                // Terminate - UnknownSequence.
                // Either way, message has been verified and does not belong to this thread.
                if (info != null)
                {
                    return;
                }

                try
                {
                    info = WsrmMessageInfo.Get(this.settings.MessageVersion, reliableMessagingVersion,
                                               this.binder.Channel, this.binder.GetInnerSession(), reply);
                    this.session.ProcessInfo(info, null, true);
                    this.session.VerifyDuplexProtocolElements(info, null, true);

                    WsrmFault fault = close
                        ? WsrmUtilities.ValidateCloseSequenceResponse(this.session, this.closeRequestor.MessageId, info,
                                                                      this.connection.Last)
                        : WsrmUtilities.ValidateTerminateSequenceResponse(this.session, this.terminateRequestor.MessageId,
                                                                          info, this.connection.Last);

                    if (fault != null)
                    {
                        this.session.OnLocalFault(null, fault, null);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(fault.CreateException());
                    }
                }
                finally
                {
                    reply.Close();
                }
            }
            else
            {
                throw Fx.AssertAndThrow("Reliable messaging version not supported.");
            }
        }
Exemple #50
0
        public static CreateSequenceInfo Create(MessageVersion messageVersion,
                                                ReliableMessagingVersion reliableMessagingVersion, ISecureConversationSession securitySession,
                                                XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                Fx.Assert("Argument reader cannot be null.");
            }

            try
            {
                CreateSequenceInfo    info = new CreateSequenceInfo();
                WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
                XmlDictionaryString   wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);
                reader.ReadStartElement(wsrmFeb2005Dictionary.CreateSequence, wsrmNs);

                info.AcksTo = EndpointAddress.ReadFrom(messageVersion.Addressing, reader, wsrmFeb2005Dictionary.AcksTo, wsrmNs);

                if (reader.IsStartElement(wsrmFeb2005Dictionary.Expires, wsrmNs))
                {
                    info.Expires = reader.ReadElementContentAsTimeSpan();
                }

                if (reader.IsStartElement(wsrmFeb2005Dictionary.Offer, wsrmNs))
                {
                    reader.ReadStartElement();

                    reader.ReadStartElement(wsrmFeb2005Dictionary.Identifier, wsrmNs);
                    info.OfferIdentifier = reader.ReadContentAsUniqueId();
                    reader.ReadEndElement();

                    bool             wsrm11           = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;
                    Wsrm11Dictionary wsrm11Dictionary = wsrm11 ? DXD.Wsrm11Dictionary : null;

                    if (wsrm11)
                    {
                        EndpointAddress endpoint = EndpointAddress.ReadFrom(messageVersion.Addressing, reader,
                                                                            wsrm11Dictionary.Endpoint, wsrmNs);

                        if (endpoint.Uri != info.AcksTo.Uri)
                        {
                            string  reason     = SR.GetString(SR.CSRefusedAcksToMustEqualEndpoint);
                            Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
                        }
                    }

                    if (reader.IsStartElement(wsrmFeb2005Dictionary.Expires, wsrmNs))
                    {
                        info.OfferExpires = reader.ReadElementContentAsTimeSpan();
                    }

                    if (wsrm11)
                    {
                        if (reader.IsStartElement(wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs))
                        {
                            string incompleteSequenceBehavior = reader.ReadElementContentAsString();

                            if ((incompleteSequenceBehavior != Wsrm11Strings.DiscardEntireSequence) &&
                                (incompleteSequenceBehavior != Wsrm11Strings.DiscardFollowingFirstGap) &&
                                (incompleteSequenceBehavior != Wsrm11Strings.NoDiscard))
                            {
                                string  reason     = SR.GetString(SR.CSRefusedInvalidIncompleteSequenceBehavior);
                                Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                          WsrmMessageInfo.CreateInternalFaultException(faultReply, reason,
                                                                                       new ProtocolException(reason)));
                            }

                            // Otherwise ignore the value.
                        }
                    }

                    while (reader.IsStartElement())
                    {
                        reader.Skip();
                    }

                    reader.ReadEndElement();
                }

                // Check for security only if we expect a soap security session.
                if (securitySession != null)
                {
                    bool hasValidToken = false;

                    // Since the security element is amongst the extensible elements (i.e. there is no
                    // gaurantee of ordering or placement), a loop is required to attempt to parse the
                    // security element.
                    while (reader.IsStartElement())
                    {
                        if (securitySession.TryReadSessionTokenIdentifier(reader))
                        {
                            hasValidToken = true;
                            break;
                        }

                        reader.Skip();
                    }

                    if (!hasValidToken)
                    {
                        string  reason     = SR.GetString(SR.CSRefusedRequiredSecurityElementMissing);
                        Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
                    }
                }

                while (reader.IsStartElement())
                {
                    reader.Skip();
                }

                reader.ReadEndElement();

                if (reader.IsStartElement())
                {
                    string  reason     = SR.GetString(SR.CSRefusedUnexpectedElementAtEndOfCSMessage);
                    Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason)));
                }

                return(info);
            }
            catch (XmlException e)
            {
                string  reason     = SR.GetString(SR.CouldNotParseWithAction, WsrmIndex.GetCreateSequenceActionString(reliableMessagingVersion));
                Message faultReply = WsrmUtilities.CreateCSRefusedProtocolFault(messageVersion, reliableMessagingVersion, reason);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmMessageInfo.CreateInternalFaultException(faultReply, reason, new ProtocolException(reason, e)));
            }
        }
 protected override void ProcessSequencedItem(IReplySessionChannel channel, RequestContext context, ReliableInputSessionChannelOverReply reliableChannel, WsrmMessageInfo info, bool newChannel)
 {
     if (!newChannel && !reliableChannel.Binder.UseNewChannel(channel))
     {
         context.RequestMessage.Close();
         context.Abort();
         channel.Abort();
     }
     else
     {
         reliableChannel.ProcessDemuxedRequest(reliableChannel.Binder.WrapRequestContext(context), info);
     }
 }
 private void ProcessRequest(RequestContext context, WsrmMessageInfo info)
 {
     bool flag = true;
     bool flag2 = true;
     try
     {
         EndpointAddress address;
         bool flag3;
         if (!base.ReliableSession.ProcessInfo(info, context))
         {
             flag = false;
             flag2 = false;
             return;
         }
         if (!base.ReliableSession.VerifySimplexProtocolElements(info, context))
         {
             flag = false;
             flag2 = false;
             return;
         }
         base.ReliableSession.OnRemoteActivity(false);
         if (info.CreateSequenceInfo == null)
         {
             goto Label_0104;
         }
         if (WsrmUtilities.ValidateCreateSequence<IInputSessionChannel>(info, base.Listener, base.Binder.Channel, out address))
         {
             Message response = WsrmUtilities.CreateCreateSequenceResponse(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion, false, info.CreateSequenceInfo, base.Listener.Ordered, base.ReliableSession.InputID, address);
             using (context)
             {
                 using (response)
                 {
                     if (base.Binder.AddressResponse(info.Message, response))
                     {
                         context.Reply(response, base.DefaultSendTimeout);
                     }
                 }
                 goto Label_00FB;
             }
         }
         base.ReliableSession.OnLocalFault(info.FaultException, info.FaultReply, context);
     Label_00FB:
         flag = false;
         flag2 = false;
         return;
     Label_0104:
         flag3 = false;
         bool allAdded = false;
         bool flag5 = false;
         WsrmFault fault = null;
         Message message2 = null;
         Exception e = null;
         bool flag6 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005;
         bool flag7 = base.Listener.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;
         bool flag8 = info.AckRequestedInfo != null;
         if (info.SequencedMessageInfo != null)
         {
             lock (base.ThisLock)
             {
                 if (base.Aborted || (base.State == CommunicationState.Faulted))
                 {
                     return;
                 }
                 long sequenceNumber = info.SequencedMessageInfo.SequenceNumber;
                 bool isLast = flag6 && info.SequencedMessageInfo.LastMessage;
                 if (!base.Connection.IsValid(sequenceNumber, isLast))
                 {
                     if (flag6)
                     {
                         fault = new LastMessageNumberExceededFault(base.ReliableSession.InputID);
                     }
                     else
                     {
                         message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion);
                         if (PerformanceCounters.PerformanceCountersEnabled)
                         {
                             PerformanceCounters.MessageDropped(base.perfCounterId);
                         }
                     }
                 }
                 else if (base.Connection.Ranges.Contains(sequenceNumber))
                 {
                     if (PerformanceCounters.PerformanceCountersEnabled)
                     {
                         PerformanceCounters.MessageDropped(base.perfCounterId);
                     }
                 }
                 else if (flag6 && (info.Action == "http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage"))
                 {
                     base.Connection.Merge(sequenceNumber, isLast);
                     allAdded = base.Connection.AllAdded;
                 }
                 else if (base.State == CommunicationState.Closing)
                 {
                     if (flag6)
                     {
                         fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSessionClosedBeforeDone"), System.ServiceModel.SR.GetString("SessionClosedBeforeDone"));
                     }
                     else
                     {
                         message2 = new SequenceClosedFault(base.ReliableSession.InputID).CreateMessage(base.Listener.MessageVersion, base.Listener.ReliableMessagingVersion);
                         if (PerformanceCounters.PerformanceCountersEnabled)
                         {
                             PerformanceCounters.MessageDropped(base.perfCounterId);
                         }
                     }
                 }
                 else if (base.DeliveryStrategy.CanEnqueue(sequenceNumber) && (base.Listener.Ordered || base.Connection.CanMerge(sequenceNumber)))
                 {
                     base.Connection.Merge(sequenceNumber, isLast);
                     flag3 = base.DeliveryStrategy.Enqueue(info.Message, sequenceNumber);
                     allAdded = base.Connection.AllAdded;
                     flag2 = false;
                 }
                 else if (PerformanceCounters.PerformanceCountersEnabled)
                 {
                     PerformanceCounters.MessageDropped(base.perfCounterId);
                 }
                 goto Label_05CE;
             }
         }
         if (flag6 && (info.TerminateSequenceInfo != null))
         {
             bool flag11;
             lock (base.ThisLock)
             {
                 flag11 = !base.Connection.Terminate();
             }
             if (!flag11)
             {
                 return;
             }
             fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedEarlyTerminateSequence"), System.ServiceModel.SR.GetString("EarlyTerminateSequence"));
         }
         else if (flag7 && ((info.TerminateSequenceInfo != null) || (info.CloseSequenceInfo != null)))
         {
             bool flag13 = info.TerminateSequenceInfo != null;
             WsrmRequestInfo info2 = flag13 ? ((WsrmRequestInfo) info.TerminateSequenceInfo) : ((WsrmRequestInfo) info.CloseSequenceInfo);
             long last = flag13 ? info.TerminateSequenceInfo.LastMsgNumber : info.CloseSequenceInfo.LastMsgNumber;
             if (!WsrmUtilities.ValidateWsrmRequest(base.ReliableSession, info2, base.Binder, context))
             {
                 flag2 = false;
                 flag = false;
                 return;
             }
             bool isLastLargeEnough = true;
             bool flag15 = true;
             lock (base.ThisLock)
             {
                 if (!base.Connection.IsLastKnown)
                 {
                     if (flag13)
                     {
                         if (base.Connection.SetTerminateSequenceLast(last, out isLastLargeEnough))
                         {
                             allAdded = true;
                         }
                         else if (isLastLargeEnough)
                         {
                             e = new ProtocolException(System.ServiceModel.SR.GetString("EarlyTerminateSequence"));
                         }
                     }
                     else
                     {
                         allAdded = base.Connection.SetCloseSequenceLast(last);
                         isLastLargeEnough = allAdded;
                     }
                     if (allAdded)
                     {
                         base.ReliableSession.SetFinalAck(base.Connection.Ranges);
                         base.DeliveryStrategy.Dispose();
                     }
                 }
                 else
                 {
                     flag15 = last == base.Connection.Last;
                     if ((flag13 && flag15) && base.Connection.IsSequenceClosed)
                     {
                         flag5 = true;
                     }
                 }
             }
             if (!isLastLargeEnough)
             {
                 fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedSmallLastMsgNumber"), System.ServiceModel.SR.GetString("SmallLastMsgNumberExceptionString"));
             }
             else if (!flag15)
             {
                 fault = SequenceTerminatedFault.CreateProtocolFault(base.ReliableSession.InputID, System.ServiceModel.SR.GetString("SequenceTerminatedInconsistentLastMsgNumber"), System.ServiceModel.SR.GetString("InconsistentLastMsgNumberExceptionString"));
             }
             else
             {
                 message2 = flag13 ? WsrmUtilities.CreateTerminateResponseMessage(base.Listener.MessageVersion, info2.MessageId, base.ReliableSession.InputID) : WsrmUtilities.CreateCloseSequenceResponse(base.Listener.MessageVersion, info2.MessageId, base.ReliableSession.InputID);
                 flag8 = true;
             }
         }
     Label_05CE:
         if (fault != null)
         {
             base.ReliableSession.OnLocalFault(fault.CreateException(), fault, context);
             flag2 = false;
             flag = false;
         }
         else
         {
             if ((message2 != null) && flag8)
             {
                 base.AddAcknowledgementHeader(message2);
             }
             else if (message2 == null)
             {
                 message2 = base.CreateAcknowledgmentMessage();
             }
             using (message2)
             {
                 context.Reply(message2);
             }
             if (flag5)
             {
                 lock (base.ThisLock)
                 {
                     base.Connection.Terminate();
                 }
             }
             if (e != null)
             {
                 base.ReliableSession.OnRemoteFault(e);
             }
             else
             {
                 if (flag3)
                 {
                     base.Dispatch();
                 }
                 if (allAdded)
                 {
                     ActionItem.Schedule(new Action<object>(this.ShutdownCallback), null);
                 }
             }
         }
     }
     finally
     {
         if (flag2)
         {
             info.Message.Close();
         }
         if (flag)
         {
             context.Close();
         }
     }
 }