예제 #1
0
        public static CloseSequenceInfo Create(XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                Fx.Assert("Argument reader cannot be null.");
            }

            CloseSequenceInfo closeSequenceInfo = new CloseSequenceInfo();

            XmlDictionaryString wsrmNs           = WsrmIndex.GetNamespace(ReliableMessagingVersion.WSReliableMessaging11);
            Wsrm11Dictionary    wsrm11Dictionary = DXD.Wsrm11Dictionary;

            reader.ReadStartElement(wsrm11Dictionary.CloseSequence, wsrmNs);
            reader.ReadStartElement(XD.WsrmFeb2005Dictionary.Identifier, wsrmNs);
            closeSequenceInfo.Identifier = reader.ReadContentAsUniqueId();
            reader.ReadEndElement();

            if (reader.IsStartElement(wsrm11Dictionary.LastMsgNumber, wsrmNs))
            {
                reader.ReadStartElement();
                closeSequenceInfo.LastMsgNumber = WsrmUtilities.ReadSequenceNumber(reader, false);
                reader.ReadEndElement();
            }

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

            reader.ReadEndElement();

            return(closeSequenceInfo);
        }
예제 #2
0
        public MessageNumberRolloverFault(FaultCode code, FaultReason reason, XmlDictionaryReader detailReader,
                                          ReliableMessagingVersion reliableMessagingVersion)
            : base(code, WsrmFeb2005Strings.MessageNumberRollover, reason, true, true)
        {
            try
            {
                this.SequenceID = WsrmUtilities.ReadIdentifier(detailReader, reliableMessagingVersion);

                if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
                {
                    detailReader.ReadStartElement(DXD.Wsrm11Dictionary.MaxMessageNumber,
                                                  WsrmIndex.GetNamespace(reliableMessagingVersion));

                    string maxMessageNumberString = detailReader.ReadContentAsString();
                    ulong  maxMessageNumber;
                    if (!UInt64.TryParse(maxMessageNumberString, out maxMessageNumber) ||
                        (maxMessageNumber <= 0))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(
                                                                                      SR.GetString(SR.InvalidSequenceNumber, maxMessageNumber)));
                    }
                    // otherwise ignore value

                    detailReader.ReadEndElement();
                }
            }
            finally
            {
                detailReader.Close();
            }
        }
 private void PollingCallback()
 {
     using (Message message = WsrmUtilities.CreateAckRequestedMessage(base.Settings.MessageVersion, base.Settings.ReliableMessagingVersion, base.ReliableSession.OutputID))
     {
         base.Binder.Send(message, base.DefaultSendTimeout);
     }
 }
예제 #4
0
        // Must call in a lock(this.ThisLock).
        private MessageAttemptInfo AddToWindow(Message message, bool isLast, object state)
        {
            MessageAttemptInfo attemptInfo = default(MessageAttemptInfo);
            long sequenceNumber;

            sequenceNumber = _windowStart + _window.Count;
            WsrmUtilities.AddSequenceHeader(_reliableMessagingVersion, message, _id, sequenceNumber, isLast);

            if (_requestAcks && (_window.Count == _windowSize - 1 || QuotaRemaining == 1)) // can't add any more
            {
                message.Properties.AllowOutputBatching = false;
                WsrmUtilities.AddAckRequestedHeader(_reliableMessagingVersion, message, _id);
            }

            if (_window.Count == 0)
            {
                _retryTimer.Set(Timeout);
            }

            _window.Add(message, Now, state);
            QuotaRemaining--;
            if (isLast)
            {
                Last = sequenceNumber;
            }

            int index = (int)(sequenceNumber - _windowStart);

            attemptInfo = new MessageAttemptInfo(_window.GetMessage(index), sequenceNumber, 0, state);

            return(attemptInfo);
        }
 private void AddAcknowledgementHeader(Message message, bool force)
 {
     if (this.ranges.Count != 0)
     {
         WsrmUtilities.AddAcknowledgementHeader(this.settings.ReliableMessagingVersion, message, this.session.InputID, this.ranges, this.isLastKnown);
     }
 }
        private TimeSpan GetPollingInterval()
        {
            switch (this.pollingMode)
            {
            case PollingMode.Idle:
                return(Ticks.ToTimeSpan(Ticks.FromTimeSpan(base.Settings.InactivityTimeout) / 2L));

            case PollingMode.KeepAlive:
                return(WsrmUtilities.CalculateKeepAliveInterval(base.Settings.InactivityTimeout, base.Settings.MaxRetryCount));

            case PollingMode.FastPolling:
            {
                TimeSpan span  = WsrmUtilities.CalculateKeepAliveInterval(base.Settings.InactivityTimeout, base.Settings.MaxRetryCount);
                TimeSpan span2 = Ticks.ToTimeSpan(Ticks.FromTimeSpan(this.binder.DefaultSendTimeout) / 2L);
                if (span2 >= span)
                {
                    return(span);
                }
                return(span2);
            }

            case PollingMode.NotPolling:
                return(TimeSpan.MaxValue);
            }
            throw Fx.AssertAndThrow("Unknown polling mode.");
        }
        private async Task TerminateSequenceAsync(TimeSpan timeout)
        {
            ReliableMessagingVersion reliableMessagingVersion = Settings.ReliableMessagingVersion;

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
            {
                _session.CloseSession();
                Message message = WsrmUtilities.CreateTerminateMessage(Settings.MessageVersion,
                                                                       reliableMessagingVersion, _session.OutputID);
                await OnConnectionSendMessageAsync(message, timeout, MaskingMode.Handled);
            }
            else if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                CreateTerminateRequestor();
                Message terminateReply = await _terminateRequestor.RequestAsync(timeout);

                if (terminateReply != null)
                {
                    ProcessCloseOrTerminateReply(false, terminateReply);
                }
            }
            else
            {
                throw Fx.AssertAndThrow("Reliable messaging version not supported.");
            }
        }
        private Message CreateAckRequestedMessage()
        {
            Message message = WsrmUtilities.CreateAckRequestedMessage(this.settings.MessageVersion, this.settings.ReliableMessagingVersion, this.session.OutputID);

            this.AddAcknowledgementHeader(message, true);
            return(message);
        }
        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);
        }
 private void PollingCallback()
 {
     using (Message message = WsrmUtilities.CreateAckRequestedMessage(this.Settings.MessageVersion, this.Settings.ReliableMessagingVersion, this.ReliableSession.OutputID))
     {
         this.OnConnectionSendMessage(message, base.DefaultSendTimeout, MaskingMode.All);
     }
 }
        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();
                }
            }
        }
        private IAsyncResult OnConnectionBeginSendAckRequestedHandler(TimeSpan timeout, AsyncCallback callback, object state)
        {
            this.session.OnLocalActivity();
            Message message = WsrmUtilities.CreateAckRequestedMessage(this.settings.MessageVersion, this.settings.ReliableMessagingVersion, this.ReliableSession.OutputID);

            return(this.OnConnectionBeginSendMessage(message, timeout, callback, state));
        }
예제 #13
0
        // Two error cases:
        // (1) The sequence contains holes.
        // (2) TerminateSequence.LastMsgNumber < last received message number.
        // In both cases the channel should be faulted. In case (2) the channel should send a fault.
        public bool SetTerminateSequenceLast(long last, out bool isLastLargeEnough)
        {
            WsrmUtilities.AssertWsrm11(_reliableMessagingVersion);
            isLastLargeEnough = true;

            // unspecified last
            if (last < 1)
            {
                return(false);
            }

            int  rangeCount   = Ranges.Count;
            long lastReceived = (rangeCount > 0) ? Ranges[rangeCount - 1].Upper : 0;

            // last is too small to be valid
            if (last < lastReceived)
            {
                isLastLargeEnough = false;
                return(false);
            }

            // there is a hole in the sequence
            if ((rangeCount > 1) || (last > lastReceived))
            {
                return(false);
            }

            SetLast(last);
            return(true);
        }
예제 #14
0
        TimeSpan GetPollingInterval()
        {
            switch (this.pollingMode)
            {
            case PollingMode.Idle:
                return(Ticks.ToTimeSpan(Ticks.FromTimeSpan(this.Settings.InactivityTimeout) / 2));

            case PollingMode.KeepAlive:
                return(WsrmUtilities.CalculateKeepAliveInterval(this.Settings.InactivityTimeout, this.Settings.MaxRetryCount));

            case PollingMode.NotPolling:
                return(TimeSpan.MaxValue);

            case PollingMode.FastPolling:
                TimeSpan keepAliveInterval   = WsrmUtilities.CalculateKeepAliveInterval(this.Settings.InactivityTimeout, this.Settings.MaxRetryCount);
                TimeSpan fastPollingInterval = Ticks.ToTimeSpan(Ticks.FromTimeSpan(this.binder.DefaultSendTimeout) / 2);

                if (fastPollingInterval < keepAliveInterval)
                {
                    return(fastPollingInterval);
                }
                else
                {
                    return(keepAliveInterval);
                }

            default:
                throw Fx.AssertAndThrow("Unknown polling mode.");
            }
        }
        void TerminateSequence(TimeSpan timeout)
        {
            ReliableMessagingVersion reliableMessagingVersion = this.settings.ReliableMessagingVersion;

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
            {
                this.session.CloseSession();
                Message message = WsrmUtilities.CreateTerminateMessage(this.settings.MessageVersion,
                                                                       reliableMessagingVersion, this.session.OutputID);
                this.OnConnectionSendMessage(message, timeout, MaskingMode.Handled);
            }
            else if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                this.CreateTerminateRequestor();
                Message terminateReply = this.terminateRequestor.Request(timeout);

                if (terminateReply != null)
                {
                    this.ProcessCloseOrTerminateReply(false, terminateReply);
                }
            }
            else
            {
                throw Fx.AssertAndThrow("Reliable messaging version not supported.");
            }
        }
예제 #16
0
        public static WsrmSequencedMessageInfo ReadHeader(ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader, MessageHeaderInfo header)
        {
            WsrmFeb2005Dictionary dictionary   = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString   namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement();
            reader.ReadStartElement(dictionary.Identifier, namespaceUri);
            UniqueId sequenceID = reader.ReadContentAsUniqueId();

            reader.ReadEndElement();
            reader.ReadStartElement(dictionary.MessageNumber, namespaceUri);
            long sequenceNumber = WsrmUtilities.ReadSequenceNumber(reader);

            reader.ReadEndElement();
            bool lastMessage = false;

            if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && reader.IsStartElement(dictionary.LastMessage, namespaceUri))
            {
                WsrmUtilities.ReadEmptyElement(reader);
                lastMessage = true;
            }
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();
            return(new WsrmSequencedMessageInfo(sequenceID, sequenceNumber, lastMessage, header));
        }
        private void Reconnect()
        {
            bool flag = true;

            try
            {
                Message      message = WsrmUtilities.CreateAckRequestedMessage(base.Settings.MessageVersion, base.Settings.ReliableMessagingVersion, base.ReliableSession.OutputID);
                TimeSpan     timeout = this.closing ? this.closeTimeoutHelper.RemainingTime() : this.DefaultCloseTimeout;
                IAsyncResult result  = base.Binder.BeginSend(message, timeout, onReconnectComplete, this);
                flag = false;
                if (result.CompletedSynchronously)
                {
                    this.HandleReconnectComplete(result);
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (!flag)
                {
                    throw;
                }
                this.WaitForReconnect();
            }
        }
 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);
         }
     }
 }
        // Must call in a lock(this.ThisLock).
        MessageAttemptInfo AddToWindow(Message message, bool isLast, object state)
        {
            MessageAttemptInfo attemptInfo = default(MessageAttemptInfo);
            Int64 sequenceNumber;

            sequenceNumber = this.windowStart + this.window.Count;
            WsrmUtilities.AddSequenceHeader(this.reliableMessagingVersion, message, this.id, sequenceNumber, isLast);

            if (this.requestAcks && (this.window.Count == this.windowSize - 1 || this.quotaRemaining == 1)) // can't add any more
            {
                message.Properties.AllowOutputBatching = false;
                WsrmUtilities.AddAckRequestedHeader(this.reliableMessagingVersion, message, this.id);
            }

            if (this.window.Count == 0)
            {
                this.retryTimer.Set(this.Timeout);
            }

            this.window.Add(message, Now, state);
            this.quotaRemaining--;
            if (isLast)
            {
                this.last = sequenceNumber;
            }

            int index = (int)(sequenceNumber - this.windowStart);

            attemptInfo = new MessageAttemptInfo(this.window.GetMessage(index), sequenceNumber, 0, state);

            return(attemptInfo);
        }
 private void AddFinalRanges()
 {
     if (this.finalRanges != null)
     {
         WsrmUtilities.AddAcknowledgementHeader(this.settings.ReliableMessagingVersion, this.terminatingFault, this.InputID, this.finalRanges, true);
     }
 }
 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 async Task PollingAsyncCallback()
 {
     using (Message request = WsrmUtilities.CreateAckRequestedMessage(Settings.MessageVersion,
                                                                      Settings.ReliableMessagingVersion, ReliableSession.OutputID))
     {
         await OnConnectionSendMessageAsync(request, DefaultSendTimeout, MaskingMode.All);
     }
 }
 private void OnConnectionSendAckRequestedHandler(TimeSpan timeout)
 {
     this.session.OnLocalActivity();
     using (Message message = WsrmUtilities.CreateAckRequestedMessage(this.settings.MessageVersion, this.settings.ReliableMessagingVersion, this.ReliableSession.OutputID))
     {
         this.OnConnectionSend(message, timeout, false, true);
     }
 }
예제 #24
0
        private Message CreateAckRequestedMessage()
        {
            Message request = WsrmUtilities.CreateAckRequestedMessage(settings.MessageVersion,
                                                                      settings.ReliableMessagingVersion, session.OutputID);

            AddAcknowledgementHeader(request, true);
            return(request);
        }
 private async Task OnConnectionSendAckRequestedAsyncHandler(TimeSpan timeout)
 {
     _session.OnLocalActivity();
     using (Message message = WsrmUtilities.CreateAckRequestedMessage(Settings.MessageVersion,
                                                                      Settings.ReliableMessagingVersion, ReliableSession.OutputID))
     {
         await OnConnectionSendAsync(message, timeout, false, true);
     }
 }
예제 #26
0
 void AddFinalRanges()
 {
     // This relies on the assumption that acknowledgements can be piggybacked on sequence
     // faults for the converse sequence.
     if (this.finalRanges != null)
     {
         WsrmUtilities.AddAcknowledgementHeader(this.settings.ReliableMessagingVersion,
                                                this.terminatingFault, this.InputID, this.finalRanges, true);
     }
 }
예제 #27
0
        private void AddAcknowledgementHeader(Message message, bool force)
        {
            if (ranges.Count == 0)
            {
                return;
            }

            WsrmUtilities.AddAcknowledgementHeader(settings.ReliableMessagingVersion, message,
                                                   session.InputID, ranges, isLastKnown);
        }
예제 #28
0
 static UniqueId ParseDetail(XmlDictionaryReader reader, ReliableMessagingVersion reliableMessagingVersion)
 {
     try
     {
         return(WsrmUtilities.ReadIdentifier(reader, reliableMessagingVersion));
     }
     finally
     {
         reader.Close();
     }
 }
        protected Message CreateAcknowledgmentMessage()
        {
            int bufferRemaining = -1;

            if (this.Listener.FlowControlEnabled)
            {
                bufferRemaining     = this.Listener.MaxTransferWindowSize - this.deliveryStrategy.EnqueuedCount;
                this.AdvertisedZero = bufferRemaining == 0;
            }
            return(WsrmUtilities.CreateAcknowledgmentMessage(this.listener.MessageVersion, this.listener.ReliableMessagingVersion, this.session.InputID, this.connection.Ranges, this.connection.IsLastKnown, bufferRemaining));
        }
        protected void AddAcknowledgementHeader(Message message)
        {
            int bufferRemaining = -1;

            if (this.Listener.FlowControlEnabled)
            {
                bufferRemaining     = this.Listener.MaxTransferWindowSize - this.deliveryStrategy.EnqueuedCount;
                this.AdvertisedZero = bufferRemaining == 0;
            }
            WsrmUtilities.AddAcknowledgementHeader(this.listener.ReliableMessagingVersion, message, this.session.InputID, this.connection.Ranges, this.connection.IsLastKnown, bufferRemaining);
        }