private void CreateTerminateRequestor()
        {
            ReliableRequestor requestor = this.CreateRequestor();

            this.ConfigureRequestor(requestor);
            ReliableMessagingVersion reliableMessagingVersion = this.settings.ReliableMessagingVersion;

            requestor.MessageAction = WsrmIndex.GetTerminateSequenceActionHeader(this.settings.MessageVersion.Addressing, reliableMessagingVersion);
            requestor.MessageBody   = new System.ServiceModel.Channels.TerminateSequence(reliableMessagingVersion, this.session.OutputID, this.connection.Last);
            lock (base.ThisLock)
            {
                base.ThrowIfClosed();
                this.terminateRequestor = requestor;
                this.session.CloseSession();
            }
        }
        void CreateCloseRequestor()
        {
            RequestReliableRequestor temp = new RequestReliableRequestor();

            this.ConfigureRequestor(temp);
            temp.TimeoutString1Index = SR.TimeoutOnClose;
            temp.MessageAction       = WsrmIndex.GetCloseSequenceActionHeader(
                this.settings.MessageVersion.Addressing);
            temp.MessageBody = new CloseSequence(this.session.OutputID, this.connection.Last);

            lock (this.ThisLock)
            {
                this.ThrowIfClosed();
                this.closeRequestor = temp;
            }
        }
        void CreateTerminateRequestor()
        {
            RequestReliableRequestor temp = new RequestReliableRequestor();

            this.ConfigureRequestor(temp);
            temp.MessageAction = WsrmIndex.GetTerminateSequenceActionHeader(
                this.settings.MessageVersion.Addressing, this.settings.ReliableMessagingVersion);
            temp.MessageBody = new TerminateSequence(this.settings.ReliableMessagingVersion,
                                                     this.session.OutputID, this.connection.Last);

            lock (this.ThisLock)
            {
                this.ThrowIfClosed();
                this.terminateRequestor = temp;
                this.session.CloseSession();
            }
        }
        private void UnblockClose()
        {
            if (this.connection != null)
            {
                this.connection.Fault(this);
            }
            ReliableRequestor closeRequestor = this.closeRequestor;

            if (closeRequestor != null)
            {
                closeRequestor.Fault(this);
            }
            closeRequestor = this.terminateRequestor;
            if (closeRequestor != null)
            {
                closeRequestor.Fault(this);
            }
        }
        private void CreateTerminateRequestor()
        {
            ReliableRequestor temp = CreateRequestor();

            ConfigureRequestor(temp);
            ReliableMessagingVersion reliableMessagingVersion = Settings.ReliableMessagingVersion;

            temp.MessageAction = WsrmIndex.GetTerminateSequenceActionHeader(
                Settings.MessageVersion.Addressing, reliableMessagingVersion);
            temp.MessageBody = new TerminateSequence(reliableMessagingVersion, _session.OutputID,
                                                     Connection.Last);

            lock (ThisLock)
            {
                ThrowIfClosed();
                _terminateRequestor = temp;
                _session.CloseSession();
            }
        }
        protected override void OnAbort()
        {
            if (this.connection != null)
            {
                this.connection.Abort(this);
            }
            ReliableRequestor closeRequestor = this.closeRequestor;

            if (closeRequestor != null)
            {
                closeRequestor.Abort(this);
            }
            closeRequestor = this.terminateRequestor;
            if (closeRequestor != null)
            {
                closeRequestor.Abort(this);
            }
            this.session.Abort();
        }
        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 void UnblockClose()
        {
            if (Connection != null)
            {
                Connection.Fault(this);
            }

            ReliableRequestor tempRequestor = _closeRequestor;

            if (tempRequestor != null)
            {
                tempRequestor.Fault(this);
            }

            tempRequestor = _terminateRequestor;
            if (tempRequestor != null)
            {
                tempRequestor.Fault(this);
            }
        }
        public ClientReliableSession(ChannelBase channel, IReliableFactorySettings factory, IClientReliableChannelBinder binder, FaultHelper faultHelper, UniqueId inputID) :
            base(channel, factory, binder, faultHelper)
        {
            this.binder       = binder;
            this.InputID      = inputID;
            this.pollingTimer = new InterruptibleTimer(this.GetPollingInterval(), this.OnPollingTimerElapsed, null);

            if (this.binder.Channel is IRequestChannel)
            {
                this.requestor = new RequestReliableRequestor();
            }
            else if (this.binder.Channel is IDuplexChannel)
            {
                SendReceiveReliableRequestor sendReceiveRequestor = new SendReceiveReliableRequestor();
                sendReceiveRequestor.TimeoutIsSafe = !this.ChannelSupportsOneCreateSequenceAttempt();
                this.requestor = sendReceiveRequestor;
            }
            else
            {
                Fx.Assert("This channel type is not supported");
            }

            MessageVersion           messageVersion           = this.Settings.MessageVersion;
            ReliableMessagingVersion reliableMessagingVersion = this.Settings.ReliableMessagingVersion;

            this.requestor.MessageVersion      = messageVersion;
            this.requestor.Binder              = this.binder;
            this.requestor.IsCreateSequence    = true;
            this.requestor.TimeoutString1Index = SR.TimeoutOnOpen;
            this.requestor.MessageAction       = WsrmIndex.GetCreateSequenceActionHeader(messageVersion.Addressing,
                                                                                         reliableMessagingVersion);
            if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) &&
                (this.binder.GetInnerSession() is ISecureConversationSession))
            {
                this.requestor.MessageHeader = new WsrmUsesSequenceSTRHeader();
            }
            this.requestor.MessageBody = new CreateSequence(this.Settings.MessageVersion.Addressing,
                                                            reliableMessagingVersion, this.Settings.Ordered, this.binder, this.InputID);
            this.requestor.SetRequestResponsePattern();
        }
        protected override void OnAbort()
        {
            if (Connection != null)
            {
                Connection.Abort(this);
            }

            ReliableRequestor tempRequestor = _closeRequestor;

            if (tempRequestor != null)
            {
                tempRequestor.Abort(this);
            }

            tempRequestor = _terminateRequestor;
            if (tempRequestor != null)
            {
                tempRequestor.Abort(this);
            }

            _session.Abort();
        }
        private void UnblockClose()
        {
            base.FaultPendingRequests();
            if (this.connection != null)
            {
                this.connection.Fault(this);
            }
            if (this.shutdownHandle != null)
            {
                this.shutdownHandle.Fault(this);
            }
            ReliableRequestor closeRequestor = this.closeRequestor;

            if (closeRequestor != null)
            {
                closeRequestor.Fault(this);
            }
            closeRequestor = this.terminateRequestor;
            if (closeRequestor != null)
            {
                closeRequestor.Fault(this);
            }
        }
 protected abstract WsrmFault ProcessRequestorResponse(ReliableRequestor requestor, string requestName, WsrmMessageInfo info);
 private void ConfigureRequestor(ReliableRequestor requestor)
 {
     requestor.MessageVersion = Settings.MessageVersion;
     requestor.Binder         = _binder;
     requestor.SetRequestResponsePattern();
 }
 public override void EndOpen(IAsyncResult result)
 {
     OpenAsyncResult.End(result);
     this.requestor = null;
 }