public static CreateSequenceResponseInfo Create(AddressingVersion addressingVersion, ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader)
        {
            CreateSequenceResponseInfo info         = new CreateSequenceResponseInfo();
            WsrmFeb2005Dictionary      dictionary   = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString        namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement(dictionary.CreateSequenceResponse, namespaceUri);
            reader.ReadStartElement(dictionary.Identifier, namespaceUri);
            info.Identifier = reader.ReadContentAsUniqueId();
            reader.ReadEndElement();
            if (reader.IsStartElement(dictionary.Expires, namespaceUri))
            {
                reader.ReadElementContentAsTimeSpan();
            }
            if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && reader.IsStartElement(DXD.Wsrm11Dictionary.IncompleteSequenceBehavior, namespaceUri))
            {
                string str2 = reader.ReadElementContentAsString();
                if (((str2 != "DiscardEntireSequence") && (str2 != "DiscardFollowingFirstGap")) && (str2 != "NoDiscard"))
                {
                    string message = System.ServiceModel.SR.GetString("CSResponseWithInvalidIncompleteSequenceBehavior");
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(message));
                }
            }
            if (reader.IsStartElement(dictionary.Accept, namespaceUri))
            {
                reader.ReadStartElement();
                info.AcceptAcksTo = EndpointAddress.ReadFrom(addressingVersion, reader, dictionary.AcksTo, namespaceUri);
                while (reader.IsStartElement())
                {
                    reader.Skip();
                }
                reader.ReadEndElement();
            }
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();
            return(info);
        }
 public static CreateSequenceResponseInfo Create(AddressingVersion addressingVersion, ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader)
 {
     CreateSequenceResponseInfo info = new CreateSequenceResponseInfo();
     WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary;
     XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);
     reader.ReadStartElement(dictionary.CreateSequenceResponse, namespaceUri);
     reader.ReadStartElement(dictionary.Identifier, namespaceUri);
     info.Identifier = reader.ReadContentAsUniqueId();
     reader.ReadEndElement();
     if (reader.IsStartElement(dictionary.Expires, namespaceUri))
     {
         reader.ReadElementContentAsTimeSpan();
     }
     if ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && reader.IsStartElement(DXD.Wsrm11Dictionary.IncompleteSequenceBehavior, namespaceUri))
     {
         string str2 = reader.ReadElementContentAsString();
         if (((str2 != "DiscardEntireSequence") && (str2 != "DiscardFollowingFirstGap")) && (str2 != "NoDiscard"))
         {
             string message = System.ServiceModel.SR.GetString("CSResponseWithInvalidIncompleteSequenceBehavior");
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(message));
         }
     }
     if (reader.IsStartElement(dictionary.Accept, namespaceUri))
     {
         reader.ReadStartElement();
         info.AcceptAcksTo = EndpointAddress.ReadFrom(addressingVersion, reader, dictionary.AcksTo, namespaceUri);
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return info;
 }
        public static CreateSequenceResponseInfo Create(AddressingVersion addressingVersion,
            ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                Fx.Assert("Argument reader cannot be null.");
            }

            CreateSequenceResponseInfo createSequenceResponse = new CreateSequenceResponseInfo();
            WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement(wsrmFeb2005Dictionary.CreateSequenceResponse, wsrmNs);

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

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

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                if (reader.IsStartElement(DXD.Wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs))
                {
                    string incompleteSequenceBehavior = reader.ReadElementContentAsString();

                    if ((incompleteSequenceBehavior != Wsrm11Strings.DiscardEntireSequence)
                        && (incompleteSequenceBehavior != Wsrm11Strings.DiscardFollowingFirstGap)
                        && (incompleteSequenceBehavior != Wsrm11Strings.NoDiscard))
                    {
                        string reason = SR.GetString(SR.CSResponseWithInvalidIncompleteSequenceBehavior);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(reason));
                    }

                    // Otherwise ignore the value.
                }
            }

            if (reader.IsStartElement(wsrmFeb2005Dictionary.Accept, wsrmNs))
            {
                reader.ReadStartElement();
                createSequenceResponse.AcceptAcksTo = EndpointAddress.ReadFrom(addressingVersion, reader,
                    wsrmFeb2005Dictionary.AcksTo, wsrmNs);
                while (reader.IsStartElement())
                {
                    reader.Skip();
                }
                reader.ReadEndElement();
            }

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

            reader.ReadEndElement();

            return createSequenceResponse;
        }
        public static CreateSequenceResponseInfo Create(AddressingVersion addressingVersion,
                                                        ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                Fx.Assert("Argument reader cannot be null.");
            }

            CreateSequenceResponseInfo createSequenceResponse = new CreateSequenceResponseInfo();
            WsrmFeb2005Dictionary      wsrmFeb2005Dictionary  = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString        wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement(wsrmFeb2005Dictionary.CreateSequenceResponse, wsrmNs);

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

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

            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                if (reader.IsStartElement(DXD.Wsrm11Dictionary.IncompleteSequenceBehavior, wsrmNs))
                {
                    string incompleteSequenceBehavior = reader.ReadElementContentAsString();

                    if ((incompleteSequenceBehavior != Wsrm11Strings.DiscardEntireSequence) &&
                        (incompleteSequenceBehavior != Wsrm11Strings.DiscardFollowingFirstGap) &&
                        (incompleteSequenceBehavior != Wsrm11Strings.NoDiscard))
                    {
                        string reason = SR.CSResponseWithInvalidIncompleteSequenceBehavior;
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(reason));
                    }

                    // Otherwise ignore the value.
                }
            }

            if (reader.IsStartElement(wsrmFeb2005Dictionary.Accept, wsrmNs))
            {
                reader.ReadStartElement();
                createSequenceResponse.AcceptAcksTo = EndpointAddress.ReadFrom(addressingVersion, reader,
                                                                               wsrmFeb2005Dictionary.AcksTo, wsrmNs);
                while (reader.IsStartElement())
                {
                    reader.Skip();
                }
                reader.ReadEndElement();
            }

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

            reader.ReadEndElement();

            return(createSequenceResponse);
        }
        private void ProcessCreateSequenceResponse(Message response, DateTime start)
        {
            CreateSequenceResponseInfo createSequenceResponseInfo = null;

            using (response)
            {
                if (response.IsFault)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmUtilities.CreateCSFaultException(base.Settings.MessageVersion, base.Settings.ReliableMessagingVersion, response, this.binder.Channel));
                }
                WsrmMessageInfo info2 = WsrmMessageInfo.Get(base.Settings.MessageVersion, base.Settings.ReliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(), response, true);
                if (info2.ParsingException != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("UnparsableCSResponse"), info2.ParsingException));
                }
                base.ProcessInfo(info2, null, true);
                createSequenceResponseInfo = info2.CreateSequenceResponseInfo;
                string message     = null;
                string faultReason = null;
                if (createSequenceResponseInfo == null)
                {
                    message = System.ServiceModel.SR.GetString("InvalidWsrmResponseChannelNotOpened", new object[] { "CreateSequence", info2.Action, WsrmIndex.GetCreateSequenceResponseActionString(base.Settings.ReliableMessagingVersion) });
                }
                else if (!object.Equals(createSequenceResponseInfo.RelatesTo, this.requestor.MessageId))
                {
                    message     = System.ServiceModel.SR.GetString("WsrmMessageWithWrongRelatesToExceptionString", new object[] { "CreateSequence" });
                    faultReason = System.ServiceModel.SR.GetString("WsrmMessageWithWrongRelatesToFaultString", new object[] { "CreateSequence" });
                }
                else if ((createSequenceResponseInfo.AcceptAcksTo == null) && (base.InputID != null))
                {
                    if (base.Settings.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessagingFebruary2005)
                    {
                        if (base.Settings.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11)
                        {
                            throw Fx.AssertAndThrow("Reliable messaging version not supported.");
                        }
                        message     = System.ServiceModel.SR.GetString("CSResponseOfferRejected");
                        faultReason = System.ServiceModel.SR.GetString("CSResponseOfferRejectedReason");
                    }
                    else
                    {
                        message     = System.ServiceModel.SR.GetString("CSResponseWithoutOffer");
                        faultReason = System.ServiceModel.SR.GetString("CSResponseWithoutOfferReason");
                    }
                }
                else if ((createSequenceResponseInfo.AcceptAcksTo != null) && (base.InputID == null))
                {
                    message     = System.ServiceModel.SR.GetString("CSResponseWithOffer");
                    faultReason = System.ServiceModel.SR.GetString("CSResponseWithOfferReason");
                }
                else if ((createSequenceResponseInfo.AcceptAcksTo != null) && (createSequenceResponseInfo.AcceptAcksTo.Uri != this.binder.RemoteAddress.Uri))
                {
                    message     = System.ServiceModel.SR.GetString("AcksToMustBeSameAsRemoteAddress");
                    faultReason = System.ServiceModel.SR.GetString("AcksToMustBeSameAsRemoteAddressReason");
                }
                if ((faultReason != null) && (createSequenceResponseInfo != null))
                {
                    WsrmFault fault = SequenceTerminatedFault.CreateProtocolFault(createSequenceResponseInfo.Identifier, faultReason, null);
                    base.OnLocalFault(null, fault, null);
                }
                if (message != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(message));
                }
            }
            base.InitiationTime = (TimeSpan)(DateTime.UtcNow - start);
            base.OutputID       = createSequenceResponseInfo.Identifier;
            this.pollingTimer.Set(this.GetPollingInterval());
            base.StartInactivityTimer();
        }
        void ProcessCreateSequenceResponse(Message response, DateTime start)
        {
            CreateSequenceResponseInfo createResponse = null;

            using (response)
            {
                if (response.IsFault)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(WsrmUtilities.CreateCSFaultException(
                                                                                  this.Settings.MessageVersion, this.Settings.ReliableMessagingVersion, response,
                                                                                  this.binder.Channel));
                }
                else
                {
                    WsrmMessageInfo info = WsrmMessageInfo.Get(this.Settings.MessageVersion,
                                                               this.Settings.ReliableMessagingVersion, this.binder.Channel, this.binder.GetInnerSession(),
                                                               response, true);

                    if (info.ParsingException != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.UnparsableCSResponse), info.ParsingException));
                    }

                    // this throws and sends a fault if something is wrong with the info
                    this.ProcessInfo(info, null, true);
                    createResponse = info.CreateSequenceResponseInfo;

                    string exceptionReason = null;
                    string faultReason     = null;

                    if (createResponse == null)
                    {
                        exceptionReason = SR.GetString(SR.InvalidWsrmResponseChannelNotOpened,
                                                       WsrmFeb2005Strings.CreateSequence, info.Action,
                                                       WsrmIndex.GetCreateSequenceResponseActionString(this.Settings.ReliableMessagingVersion));
                    }
                    else if (!object.Equals(createResponse.RelatesTo, this.requestor.MessageId))
                    {
                        exceptionReason = SR.GetString(SR.WsrmMessageWithWrongRelatesToExceptionString, WsrmFeb2005Strings.CreateSequence);
                        faultReason     = SR.GetString(SR.WsrmMessageWithWrongRelatesToFaultString, WsrmFeb2005Strings.CreateSequence);
                    }
                    else if ((createResponse.AcceptAcksTo == null) && (this.InputID != null))
                    {
                        if (this.Settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
                        {
                            exceptionReason = SR.GetString(SR.CSResponseWithoutOffer);
                            faultReason     = SR.GetString(SR.CSResponseWithoutOfferReason);
                        }
                        else if (this.Settings.ReliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
                        {
                            exceptionReason = SR.GetString(SR.CSResponseOfferRejected);
                            faultReason     = SR.GetString(SR.CSResponseOfferRejectedReason);
                        }
                        else
                        {
                            throw Fx.AssertAndThrow("Reliable messaging version not supported.");
                        }
                    }
                    else if ((createResponse.AcceptAcksTo != null) && (this.InputID == null))
                    {
                        exceptionReason = SR.GetString(SR.CSResponseWithOffer);
                        faultReason     = SR.GetString(SR.CSResponseWithOfferReason);
                    }
                    else if (createResponse.AcceptAcksTo != null && (createResponse.AcceptAcksTo.Uri != this.binder.RemoteAddress.Uri))
                    {
                        exceptionReason = SR.GetString(SR.AcksToMustBeSameAsRemoteAddress);
                        faultReason     = SR.GetString(SR.AcksToMustBeSameAsRemoteAddressReason);
                    }

                    if ((faultReason != null) && (createResponse != null))
                    {
                        UniqueId  sequenceId = createResponse.Identifier;
                        WsrmFault fault      = SequenceTerminatedFault.CreateProtocolFault(sequenceId, faultReason, null);
                        this.OnLocalFault(null, fault, null);
                    }

                    if (exceptionReason != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(exceptionReason));
                    }
                }
            }

            this.InitiationTime = DateTime.UtcNow - start;
            this.OutputID       = createResponse.Identifier;
            this.pollingTimer.Set(this.GetPollingInterval());
            base.StartInactivityTimer();
        }