ReadFullStartElement() public method

public ReadFullStartElement ( ) : void
return void
 public static XmlDictionaryReader GetReaderAtDetailContents11(string detailName, string detailNamespace, XmlDictionaryReader headerReader)
 {
     XmlDictionaryString namespaceUri = DXD.Wsrm11Dictionary.Namespace;
     headerReader.ReadFullStartElement(XD.WsrmFeb2005Dictionary.SequenceFault, namespaceUri);
     headerReader.Skip();
     headerReader.ReadFullStartElement(XD.Message12Dictionary.FaultDetail, namespaceUri);
     if (((headerReader.NodeType == XmlNodeType.Element) && !(headerReader.NamespaceURI != detailNamespace)) && !(headerReader.LocalName != detailName))
     {
         return headerReader;
     }
     headerReader.Close();
     return null;
 }
		public static void Deserialize(XmlDictionaryReader reader, out IList<DirectoryControl> controls, bool mustBePresent, bool fullChecks)
		{
			string str = null;
			string str1 = null;
			bool flag;
			byte[] numArray = null;
			controls = new List<DirectoryControl>();
			if (mustBePresent || reader.IsStartElement("controls", "http://schemas.microsoft.com/2008/1/ActiveDirectory"))
			{
				reader.ReadFullStartElement("controls", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
				while (reader.IsStartElement("control", "http://schemas.microsoft.com/2008/1/ActiveDirectory"))
				{
					string attribute = reader.GetAttribute("type");
					string attribute1 = reader.GetAttribute("criticality");
					reader.Read();
					if (!reader.IsStartElement("controlValue", "http://schemas.microsoft.com/2008/1/ActiveDirectory"))
					{
						numArray = null;
					}
					else
					{
						string attribute2 = reader.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
						if (attribute2 != null)
						{
							XmlUtility.SplitPrefix(attribute2, out str, out str1);
							numArray = reader.ReadElementContentAsBase64();
						}
						else
						{
							throw new ArgumentException();
						}
					}
					if (!string.Equals("true", attribute1))
					{
						flag = false;
					}
					else
					{
						flag = true;
					}
					DirectoryControl directoryControl = new DirectoryControl(attribute, numArray, flag, true);
					controls.Add(directoryControl);
					reader.Read();
				}
				return;
			}
			else
			{
				return;
			}
		}
 public static XmlDictionaryReader GetReaderAtDetailContentsFeb2005(string detailName, string detailNamespace, XmlDictionaryReader headerReader)
 {
     XmlDictionaryReader reader;
     try
     {
         WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary;
         XmlDictionaryString namespaceUri = dictionary.Namespace;
         XmlBuffer buffer = null;
         int sectionIndex = 0;
         int depth = headerReader.Depth;
         headerReader.ReadFullStartElement(dictionary.SequenceFault, namespaceUri);
         while (headerReader.Depth > depth)
         {
             if (((headerReader.NodeType == XmlNodeType.Element) && (headerReader.NamespaceURI == detailNamespace)) && (headerReader.LocalName == detailName))
             {
                 if (buffer != null)
                 {
                     return null;
                 }
                 buffer = new XmlBuffer(0x7fffffff);
                 try
                 {
                     sectionIndex = buffer.SectionCount;
                     buffer.OpenSection(headerReader.Quotas).WriteNode(headerReader, false);
                     continue;
                 }
                 finally
                 {
                     buffer.CloseSection();
                 }
             }
             if (headerReader.Depth == depth)
             {
                 break;
             }
             headerReader.Read();
         }
         if (buffer == null)
         {
             return null;
         }
         buffer.Close();
         reader = buffer.GetReader(sectionIndex);
     }
     finally
     {
         headerReader.Close();
     }
     return reader;
 }
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.RegisterResponse, this.coordinationXmlDictionaryStrings.Namespace);
         this.CoordinatorProtocolService = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(this.protocolVersion), reader, this.coordinationXmlDictionaryStrings.CoordinatorProtocolService, this.coordinationXmlDictionaryStrings.Namespace);
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
 }
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContextResponse, this.coordinationXmlDictionaryStrings.Namespace);
         this.CoordinationContext = Microsoft.Transactions.Wsat.Messaging.CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CoordinationContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
     catch (InvalidCoordinationContextException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
     }
 }
Esempio n. 6
0
        public static EndpointAddress ReadFrom(AddressingVersion addressingVersion, XmlDictionaryReader reader)
        {
            if (reader == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            if (addressingVersion == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");

            reader.ReadFullStartElement();
            EndpointAddress ea = ReadFromDriver(addressingVersion, reader);
            reader.ReadEndElement();
            return ea;
        }
Esempio n. 7
0
        internal static EndpointAddress ReadFrom(XmlDictionaryReader reader, out AddressingVersion version)
        {
            if (reader == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");

            reader.ReadFullStartElement();
            reader.MoveToContent();

            if (reader.IsNamespaceUri(AddressingVersion.WSAddressing10.DictionaryNamespace))
            {
                version = AddressingVersion.WSAddressing10;
            }
            else if (reader.IsNamespaceUri(AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                version = AddressingVersion.WSAddressingAugust2004;
            }
            else if (reader.NodeType != XmlNodeType.Element)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                    "reader", SR.GetString(SR.CannotDetectAddressingVersion));
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                    "reader", SR.GetString(SR.AddressingVersionNotSupported, reader.NamespaceURI));
            }

            EndpointAddress ea = ReadFromDriver(version, reader);
            reader.ReadEndElement();
            return ea;
        }
 private static OleTxTransactionHeader ReadFrom(XmlDictionaryReader reader)
 {
     System.ServiceModel.Transactions.WsatExtendedInformation wsatInfo = null;
     if (reader.IsStartElement(XD.OleTxTransactionExternalDictionary.OleTxTransaction, XD.OleTxTransactionExternalDictionary.Namespace))
     {
         Uri uri;
         string attribute = reader.GetAttribute(XD.CoordinationExternalDictionary.Identifier, CoordinationNamespace);
         if (!string.IsNullOrEmpty(attribute) && !Uri.TryCreate(attribute, UriKind.Absolute, out uri))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidWsatExtendedInfo")));
         }
         string str2 = reader.GetAttribute(XD.CoordinationExternalDictionary.Expires, CoordinationNamespace);
         uint timeout = 0;
         if (!string.IsNullOrEmpty(str2))
         {
             try
             {
                 timeout = XmlConvert.ToUInt32(str2);
             }
             catch (FormatException exception)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidWsatExtendedInfo"), exception));
             }
             catch (OverflowException exception2)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Error);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidWsatExtendedInfo"), exception2));
             }
         }
         if (!string.IsNullOrEmpty(attribute) || (timeout != 0))
         {
             wsatInfo = new System.ServiceModel.Transactions.WsatExtendedInformation(attribute, timeout);
         }
     }
     reader.ReadFullStartElement(XD.OleTxTransactionExternalDictionary.OleTxTransaction, XD.OleTxTransactionExternalDictionary.Namespace);
     byte[] propagationToken = ReadPropagationTokenElement(reader);
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return new OleTxTransactionHeader(propagationToken, wsatInfo);
 }
 public static byte[] ReadPropagationTokenElement(XmlDictionaryReader reader)
 {
     reader.ReadFullStartElement(XD.OleTxTransactionExternalDictionary.PropagationToken, XD.OleTxTransactionExternalDictionary.Namespace);
     byte[] buffer = reader.ReadContentAsBase64();
     if (buffer.Length == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidPropagationToken")));
     }
     reader.ReadEndElement();
     return buffer;
 }
        /// <summary>
        /// Reads ClaimProperties from a XmlDictionaryReader and adds them to a Dictionary.
        /// </summary>
        /// <param name="dictionaryReader">XmlDictionaryReader positioned at the element dictionary.ClaimProperties </param>
        /// <param name="dictionary">SessionDictionary to provide dictionary strings.</param>
        /// <param name="properties">Dictionary to add properties to.</param>
        /// <exception cref="ArgumentNullException">The input argument 'dictionaryReader',  'dictionary' or 'properties' is null.</exception>
        /// <exception cref="SecurityTokenException">Is thrown if the 'name' of a property is null or an empty string.</exception>
        /// <exception cref="SecurityTokenException">Is thrown if the 'value' of a property is null.</exception>
        /// <remarks>Reads 'n' properties.</remarks>
        void ReadClaimProperties(XmlDictionaryReader dictionaryReader, SessionDictionary dictionary, IDictionary<string, string> properties)
        {
            if (dictionaryReader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryReader");
            }

            if (dictionary == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionary");
            }

            if (properties == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
            }

            dictionaryReader.ReadStartElement();

            // <Property>
            while (dictionaryReader.IsStartElement(dictionary.ClaimProperty, dictionary.EmptyString))
            {
                // @Name, @Value

                string name = dictionaryReader.GetAttribute(dictionary.ClaimPropertyName, dictionary.EmptyString);
                string value = dictionaryReader.GetAttribute(dictionary.ClaimPropertyValue, dictionary.EmptyString);

                if (string.IsNullOrEmpty(name))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4249)));
                }

                if (string.IsNullOrEmpty(value))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4250)));
                }

                properties.Add(new KeyValuePair<string, string>(name, value));

                dictionaryReader.ReadFullStartElement();
                dictionaryReader.ReadEndElement();
            }

            dictionaryReader.ReadEndElement();
        }
 private static WsatRegistrationHeader ReadFrom(XmlDictionaryReader reader)
 {
     string str;
     string str2;
     reader.ReadFullStartElement(XD.DotNetAtomicTransactionExternalDictionary.RegisterInfo, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
     reader.MoveToStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
     Guid transactionId = reader.ReadElementContentAsGuid();
     if (transactionId == Guid.Empty)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderTransactionId")));
     }
     if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.ContextId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
     {
         Uri uri;
         str = reader.ReadElementContentAsString().Trim();
         if (((str.Length == 0) || (str.Length > 0x100)) || !Uri.TryCreate(str, UriKind.Absolute, out uri))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderIdentifier")));
         }
     }
     else
     {
         str = null;
     }
     if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.TokenId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
     {
         str2 = reader.ReadElementContentAsString().Trim();
         if (str2.Length == 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderTokenId")));
         }
     }
     else
     {
         str2 = null;
     }
     while (reader.IsStartElement())
     {
         reader.Skip();
     }
     reader.ReadEndElement();
     return new WsatRegistrationHeader(transactionId, str, str2);
 }
 public static EndpointAddress ReadFrom(AddressingVersion addressingVersion, XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns)
 {
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
     }
     if (addressingVersion == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion");
     }
     reader.ReadFullStartElement(localName, ns);
     EndpointAddress address = ReadFromDriver(addressingVersion, reader);
     reader.ReadEndElement();
     return address;
 }
        static OleTxTransactionHeader ReadFrom(XmlDictionaryReader reader)
        {
            WsatExtendedInformation info = null;

            if (reader.IsStartElement(XD.OleTxTransactionExternalDictionary.OleTxTransaction,
                                      XD.OleTxTransactionExternalDictionary.Namespace))
            {
                string identifier = reader.GetAttribute(XD.CoordinationExternalDictionary.Identifier, CoordinationNamespace);

                if (!string.IsNullOrEmpty(identifier))
                {
                    // Verify identifier is really a URI
                    Uri uri;
                    if (!Uri.TryCreate(identifier, UriKind.Absolute, out uri))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidWsatExtendedInfo)));
                    }
                }

                string attr = reader.GetAttribute(XD.CoordinationExternalDictionary.Expires, CoordinationNamespace);

                uint timeout = 0;
                if (!string.IsNullOrEmpty(attr))
                {
                    try
                    {
                        timeout = XmlConvert.ToUInt32(attr);
                    }
                    catch (FormatException e)
                    {
                        DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidWsatExtendedInfo), e));
                    }
                    catch (OverflowException e)
                    {
                        DiagnosticUtility.TraceHandledException(e, TraceEventType.Error);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidWsatExtendedInfo), e));
                    }
                }

                if (!string.IsNullOrEmpty(identifier) || timeout != 0)
                {
                    info = new WsatExtendedInformation(identifier, timeout);
                }
            }

            reader.ReadFullStartElement(XD.OleTxTransactionExternalDictionary.OleTxTransaction,
                                        XD.OleTxTransactionExternalDictionary.Namespace);

            byte[] propagationToken = ReadPropagationTokenElement(reader);

            // Skip extensibility elements...
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();

            return new OleTxTransactionHeader(propagationToken, info);
        }
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.Register, this.coordinationXmlDictionaryStrings.Namespace);
         reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.Protocol, this.coordinationXmlDictionaryStrings.Namespace);
         this.Protocol = WSAtomicTransactionStrings.WellKnownNameToProtocol(reader.ReadElementContentAsString().Trim(), this.protocolVersion);
         if (this.Protocol == ControlProtocol.None)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
         }
         this.ParticipantProtocolService = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(this.protocolVersion), reader, this.coordinationXmlDictionaryStrings.ParticipantProtocolService, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Loopback, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             this.Loopback = reader.ReadElementContentAsGuid();
         }
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
 }
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace))
         {
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
             }
             this.expiration = (uint) num;
             this.expiresPresent = true;
         }
         if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace))
         {
             this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion);
         }
         reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
         }
         if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             goto Label_016B;
         }
         this.IsolationLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt();
         if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot))
         {
             goto Label_016B;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
     Label_0165:
         reader.Skip();
     Label_016B:
         if (reader.IsStartElement())
         {
             goto Label_0165;
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
     catch (InvalidCoordinationContextException exception2)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2));
     }
 }
        /// <summary>
        /// Reads a single ClaimsIdentity from a XmlDictionaryReader.
        /// </summary>
        /// <param name="dictionaryReader">XmlDictionaryReader positioned at dictionary.Identity.</param>
        /// <param name="dictionary">SessionDictionary to provide dictionary strings.</param>
        /// <exception cref="ArgumentNullException">The input argument 'dictionaryReader' or 'dictionary' is null.</exception>
        /// <exception cref="SecurityTokenException">The dictionaryReader is not positioned a SessionDictionary.Identity.</exception>
        /// <returns>ClaimsIdentity</returns>
        ClaimsIdentity ReadIdentity(XmlDictionaryReader dictionaryReader, SessionDictionary dictionary)
        {
            if (dictionaryReader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryReader");
            }

            if (dictionary == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionary");
            }

            dictionaryReader.MoveToContent();

            ClaimsIdentity identity = null;

            if (!dictionaryReader.IsStartElement(dictionary.Identity, dictionary.EmptyString))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID3007, dictionaryReader.LocalName, dictionaryReader.NamespaceURI)));
            }

            // @NameClaimType
            string nameClaimType = dictionaryReader.GetAttribute(dictionary.NameClaimType, dictionary.EmptyString);

            // @RoleClaimType
            string roleClaimType = dictionaryReader.GetAttribute(dictionary.RoleClaimType, dictionary.EmptyString);

            // @WindowsLogonName (optional) => windows claims identity
            string logonName = dictionaryReader.GetAttribute(dictionary.WindowsLogonName, dictionary.EmptyString);
            string authenticationType = dictionaryReader.GetAttribute(dictionary.AuthenticationType, dictionary.EmptyString);

            if (string.IsNullOrEmpty(logonName))
            {
                identity = new ClaimsIdentity(authenticationType, nameClaimType, roleClaimType);
            }
            else
            {
                // The WindowsIdentity(string, string) c'tor does not set the Auth type. Hence we use that c'tor to get a intPtr and 
                // call the other c'tor that actually sets the authType passed in. 
                // DevDiv 279196 tracks the issue and in WindowsIdentity c'tor. Its too late to fix it in 4.5 cycle as we are in Beta and would not be
                // able to complete the analysis of the change for the current release. This should be investigated in 5.0
                WindowsIdentity winId = new WindowsIdentity(GetUpn(logonName));
                identity = new WindowsIdentity(winId.Token, authenticationType);
            }

            // @Label
            identity.Label = dictionaryReader.GetAttribute(dictionary.Label, dictionary.EmptyString);


            dictionaryReader.ReadFullStartElement();

            // <ClaimCollection>
            if (dictionaryReader.IsStartElement(dictionary.ClaimCollection, dictionary.EmptyString))
            {
                dictionaryReader.ReadStartElement();

                Collection<Claim> claims = new Collection<Claim>();
                ReadClaims(dictionaryReader, dictionary, claims);
                identity.AddClaims(claims);

                dictionaryReader.ReadEndElement();
            }

            // <Actor>
            if (dictionaryReader.IsStartElement(dictionary.Actor, dictionary.EmptyString))
            {
                dictionaryReader.ReadStartElement();

                identity.Actor = ReadIdentity(dictionaryReader, dictionary);

                dictionaryReader.ReadEndElement();
            }

            if (dictionaryReader.IsStartElement(dictionary.BootstrapToken, dictionary.EmptyString))
            {
                dictionaryReader.ReadStartElement();

                byte[] bytes = dictionaryReader.ReadContentAsBase64();
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    identity.BootstrapContext = (BootstrapContext)formatter.Deserialize(ms);
                }

                dictionaryReader.ReadEndElement();
            }

            dictionaryReader.ReadEndElement(); // Identity

            return identity;
        }
        /// <summary>
        /// Reads the ClaimsIdentites from a XmlDictionaryReader and adds them to a ClaimIdentityColleciton.
        /// </summary>
        /// <param name="dictionaryReader">XmlDictionaryReader positioned at dictionary.Identities</param>
        /// <param name="dictionary">SessionDictionary to provide dictionary strings.</param>
        /// <param name="identities">A collection of <see cref="ClaimsIdentity"/> to populate.</param>
        /// <exception cref="ArgumentNullException">The input argument 'dictionaryReader', 'dictionary' or 'identities' is null.</exception>
        /// <remarks>Reads 'n' identies and adds them to identies.</remarks>
        void ReadIdentities(XmlDictionaryReader dictionaryReader, SessionDictionary dictionary, Collection<ClaimsIdentity> identities)
        {
            if (dictionaryReader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryReader");
            }

            if (dictionary == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionary");
            }

            if (identities == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identities");
            }

            dictionaryReader.MoveToContent();

            if (dictionaryReader.IsStartElement(dictionary.Identities, dictionary.EmptyString))
            {
                dictionaryReader.ReadFullStartElement();

                while (dictionaryReader.IsStartElement(dictionary.Identity, dictionary.EmptyString))
                {
                    identities.Add(ReadIdentity(dictionaryReader, dictionary));
                }

                dictionaryReader.ReadEndElement();
            }
        }
        /// <summary>
        /// Reads a ClaimsPrincipal from a XmlDictionaryReader.
        /// </summary>
        /// <param name="dictionaryReader">XmlDictionaryReader positioned at dictionary.ClaimsPrincipal.</param>
        /// <param name="dictionary">SessionDictionary to provide dictionary strings.</param>
        /// <exception cref="ArgumentNullException">The input argument 'dictionaryReader' or 'dictionary' is null.</exception>
        /// <returns>ClaimsPrincipal</returns>
        ClaimsPrincipal ReadPrincipal(XmlDictionaryReader dictionaryReader, SessionDictionary dictionary)
        {
            if (dictionaryReader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryReader");
            }

            if (dictionary == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionary");
            }

            ClaimsPrincipal principal = null;

            Collection<ClaimsIdentity> identities = new Collection<ClaimsIdentity>();

            dictionaryReader.MoveToContent();

            if (dictionaryReader.IsStartElement(dictionary.ClaimsPrincipal, dictionary.EmptyString))
            {
                dictionaryReader.ReadFullStartElement();

                ReadIdentities(dictionaryReader, dictionary, identities);

                dictionaryReader.ReadEndElement();
            }

            // If we find a WindowsIdentity in the identities we just read, we should be creating a WindowsPrincipal using it
            WindowsIdentity wi = null;
            foreach (ClaimsIdentity identity in identities)
            {
                wi = identity as WindowsIdentity;
                if (wi != null)
                {
                    principal = new WindowsPrincipal(wi);
                    break;
                }
            }

            // If we did create a WindowsPrincipal we can remove the associated WindowsIdentity from the identities collection
            // so that we dont add it twice in the subsequent step
            if (principal != null)
            {
                identities.Remove(wi);
            }
            else if (identities.Count > 0)
            {
                // If we did not create a WindowsPrincipal, default to a ClaimsPrincipal
                principal = new ClaimsPrincipal();
            }

            if (principal != null)
            {
                // Add the identities we just read to the principal
                principal.AddIdentities(identities);
            }

            return principal;
        }
Esempio n. 19
0
        static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection)
        {
            buffer = null;
            extensionSection = -1;
            metadataSection = -1;

            // Cache address string
            if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.GetString(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
            string address = reader.ReadElementContentAsString();

            // Headers
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
            {
                headers = AddressHeaderCollection.ReadServiceParameters(reader);
            }
            else
            {
                headers = null;
            }

            // Metadata
            if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
            {
                reader.ReadFullStartElement();  // the wsa10:Metadata element is never stored in the buffer
                buffer = new XmlBuffer(short.MaxValue);
                metadataSection = 0;
                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
                writer.WriteStartElement(DummyName, DummyNamespace);
                while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
                {
                    writer.WriteNode(reader, true);
                }
                writer.Flush();
                buffer.CloseSection();
                reader.ReadEndElement();
            }

            // Extensions
            buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection);
            if (buffer != null)
            {
                buffer.Close();
            }

            // Process Address
            if (address == Addressing10Strings.Anonymous)
            {
                uri = AddressingVersion.WSAddressing10.AnonymousUri;
                if (headers == null && identity == null)
                {
                    return true;
                }
            }
            else if (address == Addressing10Strings.NoneAddress)
            {
                uri = AddressingVersion.WSAddressing10.NoneUri;
                return false;
            }
            else
            {
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
                }
            }
            return false;
        }
 private static bool ReadContentsFrom10(XmlDictionaryReader reader, out System.Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection)
 {
     buffer = null;
     extensionSection = -1;
     metadataSection = -1;
     if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, System.ServiceModel.SR.GetString("UnexpectedElementExpectingElement", new object[] { reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value })));
     }
     string uriString = reader.ReadElementContentAsString();
     if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
     {
         headers = AddressHeaderCollection.ReadServiceParameters(reader);
     }
     else
     {
         headers = null;
     }
     if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
     {
         reader.ReadFullStartElement();
         buffer = new XmlBuffer(0x7fff);
         metadataSection = 0;
         XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
         writer.WriteStartElement("Dummy", "http://Dummy");
         while ((reader.NodeType != XmlNodeType.EndElement) && !reader.EOF)
         {
             writer.WriteNode(reader, true);
         }
         writer.Flush();
         buffer.CloseSection();
         reader.ReadEndElement();
     }
     buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection);
     if (buffer != null)
     {
         buffer.Close();
     }
     if (uriString == "http://www.w3.org/2005/08/addressing/anonymous")
     {
         uri = AddressingVersion.WSAddressing10.AnonymousUri;
         if ((headers == null) && (identity == null))
         {
             return true;
         }
     }
     else
     {
         if (uriString == "http://www.w3.org/2005/08/addressing/none")
         {
             uri = AddressingVersion.WSAddressing10.NoneUri;
             return false;
         }
         if (!System.Uri.TryCreate(uriString, UriKind.Absolute, out uri))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidUriValue", new object[] { uriString, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value })));
         }
     }
     return false;
 }
 private static void ReadFrom(CoordinationContext that, XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     try
     {
         Uri uri;
         CoordinationXmlDictionaryStrings strings = CoordinationXmlDictionaryStrings.Version(protocolVersion);
         AtomicTransactionStrings strings2 = AtomicTransactionStrings.Version(protocolVersion);
         reader.ReadFullStartElement(localName, strings.Namespace);
         reader.MoveToStartElement(strings.Identifier, strings.Namespace);
         that.unknownIdentifierAttributes = ReadOtherAttributes(reader, strings.Namespace);
         that.contextId = reader.ReadElementContentAsString().Trim();
         if ((that.contextId.Length == 0) || (that.contextId.Length > 0x100))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (!Uri.TryCreate(that.contextId, UriKind.Absolute, out uri))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (reader.IsStartElement(strings.Expires, strings.Namespace))
         {
             that.unknownExpiresAttributes = ReadOtherAttributes(reader, strings.Namespace);
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
             that.expiration = (uint) num;
             that.expiresPresent = true;
         }
         reader.MoveToStartElement(strings.CoordinationType, strings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != strings2.Namespace)
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         that.registrationRef = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(protocolVersion), reader, strings.RegistrationService, strings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt();
             if (((that.IsolationLevel < System.Transactions.IsolationLevel.Serializable) || (that.IsolationLevel > System.Transactions.IsolationLevel.Unspecified)) || (that.IsolationLevel == System.Transactions.IsolationLevel.Snapshot))
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationFlags, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoFlags = (System.ServiceModel.Transactions.IsolationFlags) reader.ReadElementContentAsInt();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Description, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.description = reader.ReadElementContentAsString().Trim();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.localTxId = reader.ReadElementContentAsGuid();
         }
         if (OleTxTransactionHeader.IsStartPropagationTokenElement(reader))
         {
             that.propToken = OleTxTransactionHeader.ReadPropagationTokenElement(reader);
         }
         if (reader.IsStartElement())
         {
             XmlDocument document = new XmlDocument();
             that.unknownData = new List<System.Xml.XmlNode>(5);
             while (reader.IsStartElement())
             {
                 System.Xml.XmlNode item = document.ReadNode(reader);
                 that.unknownData.Add(item);
             }
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"), exception));
     }
 }
 internal static EndpointAddress ReadFrom(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, out AddressingVersion version)
 {
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
     }
     reader.ReadFullStartElement(localName, ns);
     reader.MoveToContent();
     if (reader.IsNamespaceUri(AddressingVersion.WSAddressing10.DictionaryNamespace))
     {
         version = AddressingVersion.WSAddressing10;
     }
     else if (reader.IsNamespaceUri(AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
     {
         version = AddressingVersion.WSAddressingAugust2004;
     }
     else
     {
         if (reader.NodeType != XmlNodeType.Element)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", System.ServiceModel.SR.GetString("CannotDetectAddressingVersion"));
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", System.ServiceModel.SR.GetString("AddressingVersionNotSupported", new object[] { reader.NamespaceURI }));
     }
     EndpointAddress address = ReadFromDriver(version, reader);
     reader.ReadEndElement();
     return address;
 }
            public override SecurityToken ReadTokenCore(XmlDictionaryReader reader, SecurityTokenResolver tokenResolver)
            {
                UniqueId contextId = null;
                byte[] encodedCookie = null;
                UniqueId generation = null;
                bool isCookieMode = false;

                Fx.Assert(reader.NodeType == XmlNodeType.Element, "");

                // check if there is an id
                string id = reader.GetAttribute(XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace);

                SecurityContextSecurityToken sct = null;

                // There needs to be at least a contextId in here.
                reader.ReadFullStartElement();
                reader.MoveToStartElement(parent.SerializerDictionary.Identifier, parent.SerializerDictionary.Namespace);
                contextId = reader.ReadElementContentAsUniqueId();
                if (CanReadGeneration(reader))
                {
                    generation = ReadGeneration(reader);
                }
                if (reader.IsStartElement(parent.SerializerDictionary.Cookie, XD.DotNetSecurityDictionary.Namespace))
                {
                    isCookieMode = true;
                    ISecurityContextSecurityTokenCache sctCache;
                    sct = TryResolveSecurityContextToken(contextId, generation, id, tokenResolver, out sctCache);
                    if (sct == null)
                    {
                        encodedCookie = reader.ReadElementContentAsBase64();
                        if (encodedCookie != null)
                        {
                            sct = cookieSerializer.CreateSecurityContextFromCookie(encodedCookie, contextId, generation, id, reader.Quotas);
                            if (sctCache != null)
                            {
                                sctCache.AddContext(sct);
                            }
                        }
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
                reader.ReadEndElement();

                if (contextId == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.NoSecurityContextIdentifier)));
                }

                if (sct == null && !isCookieMode)
                {
                    ISecurityContextSecurityTokenCache sctCache;
                    sct = TryResolveSecurityContextToken(contextId, generation, id, tokenResolver, out sctCache);
                }
                if (sct == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityContextTokenValidationException(SR.GetString(SR.SecurityContextNotRegistered, contextId, generation)));
                }
                return sct;
            }
        public static byte[] ReadPropagationTokenElement(XmlDictionaryReader reader)
        {
            reader.ReadFullStartElement(XD.OleTxTransactionExternalDictionary.PropagationToken,
                                        XD.OleTxTransactionExternalDictionary.Namespace);

            byte[] propagationToken = reader.ReadContentAsBase64();
            if (propagationToken.Length == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidPropagationToken)));
            }

            reader.ReadEndElement();

            return propagationToken;
        }
        /// <summary>
        /// Reads Claims from a XmlDictionaryReader and adds them to a ClaimCollection.
        /// </summary>
        /// <param name="dictionaryReader">XmlDictionaryReader positioned at dictionary.Claim.</param>
        /// <param name="dictionary">SessionDictionary to provide dictionary strings.</param>
        /// <param name="claims">ClaimCollection to add the claims to.</param>
        /// <exception cref="ArgumentNullException">The input argument 'dictionaryReader',  'dictionary' or 'claims' is null.</exception>
        /// <remarks>Reads 'n' claims and adds them to claims.</remarks>
        void ReadClaims(XmlDictionaryReader dictionaryReader, SessionDictionary dictionary, Collection<Claim> claims)
        {
            if (dictionaryReader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionaryReader");
            }

            if (dictionary == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dictionary");
            }

            if (claims == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("claims");
            }

            while (dictionaryReader.IsStartElement(dictionary.Claim, dictionary.EmptyString))
            {
                // @Issuer (optional), @OriginalIssuer (optional), @Type, @Value, @ValueType

                Claim claim = new Claim(dictionaryReader.GetAttribute(dictionary.Type, dictionary.EmptyString),
                                         dictionaryReader.GetAttribute(dictionary.Value, dictionary.EmptyString),
                                         dictionaryReader.GetAttribute(dictionary.ValueType, dictionary.EmptyString),
                                         dictionaryReader.GetAttribute(dictionary.Issuer, dictionary.EmptyString),
                                         dictionaryReader.GetAttribute(dictionary.OriginalIssuer, dictionary.EmptyString));

                dictionaryReader.ReadFullStartElement();

                // <Properties> (optional)
                if (dictionaryReader.IsStartElement(dictionary.ClaimProperties, dictionary.EmptyString))
                {
                    ReadClaimProperties(dictionaryReader, dictionary, claim.Properties);
                }

                dictionaryReader.ReadEndElement();

                claims.Add(claim);
            }
        }
Esempio n. 26
0
 public static Int64 ReadElementContentAsInt64(XmlDictionaryReader reader)
 {
     reader.ReadFullStartElement();
     Int64 i = reader.ReadContentAsLong();
     reader.ReadEndElement();
     return i;
 }
        /// <summary>
        /// Reads an <see cref="EndpointReference"/> from xml dictionary reader. The addressing version is defaulted to
        /// <see cref="WSAddressing10Constants.Elements.Address"/>.
        /// </summary>
        /// <param name="reader">The xml dictionary reader.</param>
        /// <returns>An <see cref="EndpointReference"/> instance.</returns>
        public static EndpointReference ReadFrom(XmlDictionaryReader reader)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            reader.ReadFullStartElement();
            reader.MoveToContent();

            if (reader.IsNamespaceUri(WSAddressing10Constants.NamespaceUri) || reader.IsNamespaceUri(WSAddressing200408Constants.NamespaceUri))
            {
                if (reader.IsStartElement(WSAddressing10Constants.Elements.Address, WSAddressing10Constants.NamespaceUri) ||
                    reader.IsStartElement(WSAddressing10Constants.Elements.Address, WSAddressing200408Constants.NamespaceUri))
                {
                    EndpointReference er = new EndpointReference(reader.ReadElementContentAsString());
                    while ( reader.IsStartElement() )
                    {
                        bool emptyElement = reader.IsEmptyElement;
                        
                        XmlReader subtreeReader = reader.ReadSubtree();
                        XmlDocument doc = new XmlDocument();
                        doc.PreserveWhitespace = true;
                        doc.Load( subtreeReader );
                        er._details.Add( doc.DocumentElement );
                        if ( !emptyElement )
                        {
                            reader.ReadEndElement();
                        }
                    }

                    reader.ReadEndElement();
                    return er;
                }
            }

            return null;
        }
Esempio n. 28
0
        public static XmlDictionaryReader GetReaderAtDetailContentsFeb2005(string detailName, string detailNamespace,
            XmlDictionaryReader headerReader)
        {
            try
            {
                WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
                XmlDictionaryString wsrmNs = wsrmFeb2005Dictionary.Namespace;
                XmlBuffer buffer = null;
                int index = 0;
                int depth = headerReader.Depth;
                headerReader.ReadFullStartElement(wsrmFeb2005Dictionary.SequenceFault, wsrmNs);

                while (headerReader.Depth > depth)
                {
                    if ((headerReader.NodeType == XmlNodeType.Element)
                        && (headerReader.NamespaceURI == detailNamespace)
                        && (headerReader.LocalName == detailName))
                    {
                        if (buffer != null)
                        {
                            return null;
                        }

                        buffer = new XmlBuffer(int.MaxValue);

                        try
                        {
                            index = buffer.SectionCount;
                            XmlDictionaryWriter writer = buffer.OpenSection(headerReader.Quotas);
                            // WriteNode moves the reader to the next sibling.
                            writer.WriteNode(headerReader, false);
                        }
                        finally
                        {
                            buffer.CloseSection();
                        }
                    }
                    else
                    {
                        if (headerReader.Depth == depth)
                            break;

                        headerReader.Read();
                    }
                }

                // Ensure at least one detail is found;
                if (buffer == null)
                {
                    return null;
                }

                // Close causes a state change.  It moves the buffer from Created to Reading.
                buffer.Close();
                XmlDictionaryReader detailReader = buffer.GetReader(index);
                return detailReader;
            }
            finally
            {
                headerReader.Close();
            }
        }
        static WsatRegistrationHeader ReadFrom(XmlDictionaryReader reader)
        {
            reader.ReadFullStartElement(XD.DotNetAtomicTransactionExternalDictionary.RegisterInfo,
                                        XD.DotNetAtomicTransactionExternalDictionary.Namespace);

            reader.MoveToStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId,
                                      XD.DotNetAtomicTransactionExternalDictionary.Namespace);

            // TransactionId
            Guid transactionId = reader.ReadElementContentAsGuid();
            if (transactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new XmlException(SR.GetString(SR.InvalidRegistrationHeaderTransactionId)));
            }

            // ContextId
            string contextId;
            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.ContextId,
                                      XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                Uri uri;
                contextId = reader.ReadElementContentAsString().Trim();
                if (contextId.Length == 0 ||
                    contextId.Length > CoordinationContext.MaxIdentifierLength ||
                    !Uri.TryCreate(contextId, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new XmlException(SR.GetString(SR.InvalidRegistrationHeaderIdentifier)));
                }
            }
            else
            {
                contextId = null;
            }

            // TokenId
            string tokenId;
            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.TokenId,
                                      XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                tokenId = reader.ReadElementContentAsString().Trim();
                if (tokenId.Length == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new XmlException(SR.GetString(SR.InvalidRegistrationHeaderTokenId)));
                }
            }
            else
            {
                tokenId = null;
            }

            // Skip unknown elements
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();

            return new WsatRegistrationHeader(transactionId, contextId, tokenId);
        }