Exemplo n.º 1
0
        public static ReceivedFault CreateFault11(XmlDictionaryReader reader, int maxBufferSize)
        {
            string str;
            string str2;

            reader.ReadStartElement(XD.MessageDictionary.Fault, XD.Message11Dictionary.Namespace);
            reader.ReadStartElement(XD.Message11Dictionary.FaultCode, XD.Message11Dictionary.FaultNamespace);
            XmlUtil.ReadContentAsQName(reader, out str2, out str);
            FaultCode code = new FaultCode(str2, str);

            reader.ReadEndElement();
            string xmlLang = reader.XmlLang;

            reader.MoveToContent();
            FaultReasonText translation = new FaultReasonText(reader.ReadElementContentAsString(XD.Message11Dictionary.FaultString.Value, XD.Message11Dictionary.FaultNamespace.Value), xmlLang);
            string          actor       = "";

            if (reader.IsStartElement(XD.Message11Dictionary.FaultActor, XD.Message11Dictionary.FaultNamespace))
            {
                actor = reader.ReadElementContentAsString();
            }
            XmlBuffer detail = null;

            if (reader.IsStartElement(XD.Message11Dictionary.FaultDetail, XD.Message11Dictionary.FaultNamespace))
            {
                detail = new XmlBuffer(maxBufferSize);
                detail.OpenSection(reader.Quotas).WriteNode(reader, false);
                detail.CloseSection();
                detail.Close();
            }
            reader.ReadEndElement();
            return(new ReceivedFault(code, new FaultReason(translation), actor, actor, detail, EnvelopeVersion.Soap11));
        }
Exemplo n.º 2
0
 public RawFaultException(XmlDictionaryReader reader) :
     base("The service returned a fault - see FaultMessage, FaultStackTrace, and FaultType.")
 {
     reader.ReadToFollowing("Message");
     m_faultMessage = reader.ReadElementContentAsString();
     m_stackTrace   = reader.ReadElementContentAsString("StackTrace", reader.NamespaceURI);
     m_type         = Type.GetType(reader.ReadElementContentAsString("Type", reader.NamespaceURI));
 }
Exemplo n.º 3
0
        static PollingDuplexSession ReadHeaderValue(XmlDictionaryReader reader)
        {
            string str  = null;
            string str2 = null;

            if (reader.IsStartElement("Duplex", "http://schemas.microsoft.com/2008/04/netduplex"))
            {
                reader.ReadStartElement();
                reader.MoveToContent();
                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement("SessionId", "http://schemas.microsoft.com/2008/04/netduplex"))
                    {
                        if (!string.IsNullOrEmpty(str2))
                        {
                            throw new InvalidOperationException("Multiple sessionId elements in a duplex header.");
                        }
                        str2 = reader.ReadElementContentAsString();
                        if (string.IsNullOrEmpty(str2))
                        {
                            throw new InvalidOperationException("Invalid sessionId element content in a duplex header.");
                        }
                    }
                    else
                    {
                        if (reader.IsStartElement("Address", "http://schemas.microsoft.com/2008/04/netduplex"))
                        {
                            if (!string.IsNullOrEmpty(str))
                            {
                                throw new InvalidOperationException("Multiple address elements in a duplex header.");
                            }
                            str = reader.ReadElementContentAsString();
                            if (string.IsNullOrEmpty(str))
                            {
                                throw new InvalidOperationException("Invalid address element in a duplex header.");
                            }
                            continue;
                        }
                        if (reader.IsStartElement("CloseSession", "http://schemas.microsoft.com/2008/04/netduplex"))
                        {
                            reader.Skip();
                            continue;
                        }
                        reader.Skip();
                    }
                }
                reader.ReadEndElement();
            }
            if (str == null)
            {
                throw new InvalidOperationException("Missing address in a duplex header.");
            }
            if (str2 == null)
            {
                throw new InvalidOperationException("Missing sessionId in a duplex header.");
            }
            return(new PollingDuplexSession(str, str2));
        }
Exemplo n.º 4
0
        private static ReceivedFault CreateFault12Driver(XmlDictionaryReader reader, int maxBufferSize, EnvelopeVersion version)
        {
            reader.ReadStartElement(XD.MessageDictionary.Fault, version.DictionaryNamespace);
            reader.ReadStartElement(XD.Message12Dictionary.FaultCode, version.DictionaryNamespace);
            FaultCode code = ReadFaultCode12Driver(reader, version);

            reader.ReadEndElement();
            List <FaultReasonText> translations = new List <FaultReasonText>();

            if (reader.IsEmptyElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.AtLeastOneFaultReasonMustBeSpecified));
            }
            else
            {
                reader.ReadStartElement(XD.Message12Dictionary.FaultReason, version.DictionaryNamespace);
                while (reader.IsStartElement(XD.Message12Dictionary.FaultText, version.DictionaryNamespace))
                {
                    translations.Add(ReadTranslation12(reader));
                }

                reader.ReadEndElement();
            }

            string actor = "";
            string node  = "";

            if (reader.IsStartElement(XD.Message12Dictionary.FaultNode, version.DictionaryNamespace))
            {
                node = reader.ReadElementContentAsString();
            }

            if (reader.IsStartElement(XD.Message12Dictionary.FaultRole, version.DictionaryNamespace))
            {
                actor = reader.ReadElementContentAsString();
            }

            XmlBuffer detail = null;

            if (reader.IsStartElement(XD.Message12Dictionary.FaultDetail, version.DictionaryNamespace))
            {
                detail = new XmlBuffer(maxBufferSize);
                XmlDictionaryWriter writer = detail.OpenSection(reader.Quotas);
                writer.WriteNode(reader, false);
                detail.CloseSection();
                detail.Close();
            }
            reader.ReadEndElement();
            FaultReason reason = new FaultReason(translations);

            return(new ReceivedFault(code, reason, actor, node, detail, version));
        }
Exemplo n.º 5
0
 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));
     }
 }
Exemplo n.º 6
0
        private static FaultReasonText ReadTranslation12(XmlDictionaryReader reader)
        {
            string xmlLang = XmlUtil.GetXmlLangAttribute(reader);
            string text    = reader.ReadElementContentAsString();

            return(new FaultReasonText(text, xmlLang));
        }
Exemplo n.º 7
0
        public virtual void ReadXml(XmlDictionaryReader reader,
                                    SamlSerializer samlSerializer,
                                    SecurityTokenSerializer keyInfoTokenSerializer,
                                    SecurityTokenResolver outOfBandTokenResolver)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (samlSerializer == null)
            {
                throw new ArgumentNullException("samlSerializer");
            }

            reader.ReadStartElement("Subject", SamlConstants.Namespace);
            NameFormat    = reader.GetAttribute("Format");
            NameQualifier = reader.GetAttribute("NameQualifier");
            Name          = reader.ReadElementContentAsString("NameIdentifier", SamlConstants.Namespace);
            reader.ReadEndElement();

            if (Name == null || Name.Length == 0)
            {
                throw new SecurityTokenException("non-zero length string must be exist for Name.");
            }
        }
Exemplo n.º 8
0
        public static void ReadElementContentAsStringDataExceedsMaxBytesPerReadQuota()
        {
            XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();

            quotas.MaxBytesPerRead = 4096;
            int contentLength = 8176;

            string              testString = new string('a', contentLength);
            string              returnedString;
            XmlDictionary       dict      = new XmlDictionary();
            XmlDictionaryString dictEntry = dict.Add("Value");

            using (var ms = new MemoryStream())
            {
                XmlDictionaryWriter xmlWriter = XmlDictionaryWriter.CreateBinaryWriter(ms, dict);
                xmlWriter.WriteElementString(dictEntry, XmlDictionaryString.Empty, testString);
                xmlWriter.Flush();
                ms.Position = 0;
                XmlDictionaryReader xmlReader = XmlDictionaryReader.CreateBinaryReader(ms, dict, quotas);
                xmlReader.Read();
                returnedString = xmlReader.ReadElementContentAsString();
            }

            Assert.Equal(testString, returnedString);
        }
Exemplo n.º 9
0
        public static PullNotificationHeader ParseHeader(OperationContext context)
        {
            try
            {
                int headerIndex = context.IncomingMessageHeaders.FindHeader(NOTIFICATION_HEADER_NAME, PULL_NOTIFICATION_NAMESPACE);
                if (headerIndex != -1)
                {
                    XmlDictionaryReader reader = context.IncomingMessageHeaders.GetReaderAtHeader(headerIndex);

                    if (reader.IsStartElement(NOTIFICATION_HEADER_NAME, PULL_NOTIFICATION_NAMESPACE))
                    {
                        reader.ReadStartElement();
                        reader.MoveToContent();

                        if (reader.IsStartElement(ADDRESS_ELEMENT_NAME, PULL_NOTIFICATION_NAMESPACE))
                        {
                            string address = reader.ReadElementContentAsString();
                            return(new PullNotificationHeader(address));
                        }
                    }
                }
                return(null);
            }
            catch (Exception excp)
            {
                logger.Error("Exception PullNotificationHeader ParseHeader. " + excp.Message);
                throw;
            }
        }
        public override ArraySegment <byte> WriteMessage(Message message,
                                                         int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            String bodyContent = null;

            lastMessage = message.Headers.Action;

            XmlDictionaryReader reader = message.GetReaderAtBodyContents();

            while (reader.Read())
            {
                if (reader.Name == "request")
                {
                    bodyContent = reader.ReadElementContentAsString();
                    break;
                }
            }
            reader.Close();

            byte[] messageBytes = System.Text.Encoding.UTF8.GetBytes(bodyContent);

            int totalLength = messageBytes.Length + messageOffset;

            byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
            Array.Copy(messageBytes, 0,
                       totalBytes, messageOffset, messageBytes.Length);

            ArraySegment <byte> buffer =
                new ArraySegment <byte>(
                    totalBytes, messageOffset, messageBytes.Length);

            return(buffer);
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Reads the X.509 Security token referenced by the XmlReader.
        /// </summary>
        /// <param name="reader">XmlReader pointing to a X.509 Security token.</param>
        /// <returns>An instance of <see cref="X509SecurityToken"/>.</returns>
        /// <exception cref="ArgumentNullException">The parameter 'reader' is null.</exception>
        /// <exception cref="XmlException">XmlReader is not pointing to an valid X509SecurityToken as
        /// defined in WS-Security X.509 Token Profile. Or the encodingType specified is other than Base64
        /// or HexBinary.</exception>
        public override SecurityToken ReadToken(XmlReader reader)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            XmlDictionaryReader dicReader = XmlDictionaryReader.CreateDictionaryReader(reader);

            if (!dicReader.IsStartElement(WSSecurity10Constants.Elements.BinarySecurityToken, WSSecurity10Constants.Namespace))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new XmlException(
                              SR.GetString(
                                  SR.ID4065,
                                  WSSecurity10Constants.Elements.BinarySecurityToken,
                                  WSSecurity10Constants.Namespace,
                                  dicReader.LocalName,
                                  dicReader.NamespaceURI)));
            }

            string valueTypeUri = dicReader.GetAttribute(WSSecurity10Constants.Attributes.ValueType, null);

            if (!StringComparer.Ordinal.Equals(valueTypeUri, WSSecurity10Constants.X509TokenType))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new XmlException(
                              SR.GetString(
                                  SR.ID4066,
                                  WSSecurity10Constants.Elements.BinarySecurityToken,
                                  WSSecurity10Constants.Namespace,
                                  WSSecurity10Constants.Attributes.ValueType,
                                  WSSecurity10Constants.X509TokenType,
                                  valueTypeUri)));
            }

            string wsuId    = dicReader.GetAttribute(WSSecurityUtilityConstants.Attributes.Id, WSSecurityUtilityConstants.Namespace);
            string encoding = dicReader.GetAttribute(WSSecurity10Constants.Attributes.EncodingType, null);

            byte[] binaryData;
            if (encoding == null || StringComparer.Ordinal.Equals(encoding, WSSecurity10Constants.Base64EncodingType))
            {
                binaryData = dicReader.ReadElementContentAsBase64();
            }
            else if (StringComparer.Ordinal.Equals(encoding, WSSecurity10Constants.HexBinaryEncodingType))
            {
                binaryData = SoapHexBinary.Parse(dicReader.ReadElementContentAsString()).Value;
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ID4068)));
            }

            return(String.IsNullOrEmpty(wsuId) ?
                   new X509SecurityToken(new X509Certificate2(binaryData)) :
                   new X509SecurityToken(new X509Certificate2(binaryData), wsuId));
        }
Exemplo n.º 13
0
        static MessageFault CreateFault12(Message message, int maxBufferSize)
        {
            FaultCode           fc   = null;
            FaultReason         fr   = null;
            string              node = null;
            XmlDictionaryReader r    = message.GetReaderAtBodyContents();

            r.ReadStartElement("Fault", message.Version.Envelope.Namespace);

            for (r.MoveToContent(); r.NodeType != XmlNodeType.EndElement; r.MoveToContent())
            {
                if (r.NamespaceURI != message.Version.Envelope.Namespace)
                {
                    r.Skip();
                    continue;
                }
                switch (r.LocalName)
                {
                case "Code":
                    fc = ReadFaultCode12(r, message.Version.Envelope.Namespace);
                    break;

                case "Reason":
                    fr = ReadFaultReason12(r, message.Version.Envelope.Namespace);
                    break;

                case "Node":
                    node = r.ReadElementContentAsString();
                    break;

                case "Role":
                    r.Skip();                      // no corresponding member to store.
                    break;

                case "Detail":
                    if (!r.IsEmptyElement)
                    {
                        return(new XmlReaderDetailMessageFault(message, r, fc, fr, null, node));
                    }
                    r.Read();
                    break;

                default:
                    throw new XmlException(String.Format("Unexpected node {0} name {1}", r.NodeType, r.Name));
                }
            }

            if (fr == null)
            {
                throw new XmlException("Reason is missing in the Fault message");
            }

            r.ReadEndElement();

            return(new SimpleMessageFault(fc, fr, false, null, null, null, node));
        }
Exemplo n.º 14
0
        public static string ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion addressingVersion)
        {
            string s = reader.ReadElementContentAsString();

            if ((s.Length <= 0) || ((s[0] > ' ') && (s[s.Length - 1] > ' ')))
            {
                return(s);
            }
            return(XmlUtil.Trim(s));
        }
Exemplo n.º 15
0
        static MessageFault CreateFault11(Message message, int maxBufferSize)
        {
            FaultCode           fc    = null;
            FaultReason         fr    = null;
            string              actor = null;
            XmlDictionaryReader r     = message.GetReaderAtBodyContents();

            r.ReadStartElement("Fault", message.Version.Envelope.Namespace);
            r.MoveToContent();

            while (r.NodeType != XmlNodeType.EndElement)
            {
                switch (r.LocalName)
                {
                case "faultcode":
                    fc = ReadFaultCode11(r);
                    break;

                case "faultstring":
                    fr = new FaultReason(r.ReadElementContentAsString());
                    break;

                case "faultactor":
                    actor = r.ReadElementContentAsString();
                    break;

                case "detail":
                    return(new XmlReaderDetailMessageFault(message, r, fc, fr, actor, null));

                default:
                    throw new XmlException(String.Format("Unexpected node {0} name {1}", r.NodeType, r.Name));
                }
                r.MoveToContent();
            }
            r.ReadEndElement();

            if (fr == null)
            {
                throw new XmlException("Reason is missing in the Fault message");
            }

            return(new SimpleMessageFault(fc, fr, false, null, null, actor, null));
        }
Exemplo n.º 16
0
 object ReadMessagePart(MessagePartDescription part, XmlDictionaryReader r)
 {
     if (part.Type == typeof(Stream))
     {
         // FIXME: it seems TransferMode.Streamed* has different serialization than .Buffered. Need to differentiate serialization somewhere (not limited to here).
         return(new MemoryStream(Convert.FromBase64String(r.ReadElementContentAsString(part.Name, part.Namespace))));
     }
     else
     {
         return(GetSerializer(part).ReadObject(r));
     }
 }
            protected override int ReadArray(XmlDictionaryReader reader, string localName, string namespaceUri, DateTime[] array, int offset, int count)
            {
                XmlJsonReader.CheckArray(array, offset, count);
                int num = 0;

                while ((num < count) && reader.IsStartElement("item", string.Empty))
                {
                    array[offset + num] = JsonReaderDelegator.ParseJsonDate(reader.ReadElementContentAsString());
                    num++;
                }
                return(num);
            }
Exemplo n.º 18
0
        public static string ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion addressingVersion)
        {
            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.Action, addressingVersion.DictionaryNamespace), "");
            string act = reader.ReadElementContentAsString();

            if (act.Length > 0 && (act[0] <= 32 || act[act.Length - 1] <= 32))
            {
                act = XmlUtil.Trim(act);
            }

            return(act);
        }
Exemplo n.º 19
0
        void ReadTokenContent()
        {
            switch (reader.NamespaceURI)
            {
            case Constants.WstNamespace:
                switch (reader.LocalName)
                {
                case "RequestType":
                    req.RequestType = reader.ReadElementContentAsString();
                    return;

                case "Entropy":
                    ReadEntropy();
                    return;

                case "KeySize":
                    req.KeySize = reader.ReadElementContentAsInt();
                    return;

                case "KeyType":
                    req.KeyType = reader.ReadElementContentAsString();
                    return;

                case "ComputedKeyAlgorithm":
                    req.ComputedKeyAlgorithm = reader.ReadElementContentAsString();
                    return;
                }
                break;

            case Constants.WspNamespace:
                switch (reader.LocalName)
                {
                case "AppliesTo":
                    ReadAppliesTo();
                    return;
                }
                break;
            }
            throw new XmlException(String.Format("Unexpected RequestSecurityToken content element. Name is {0} and namespace URI is {1}{2}", reader.Name, reader.NamespaceURI, LineInfo()));
        }
Exemplo n.º 20
0
        public static ReceivedFault CreateFault11(XmlDictionaryReader reader, int maxBufferSize)
        {
            reader.ReadStartElement(XD.MessageDictionary.Fault, XD.Message11Dictionary.Namespace);
            string ns;
            string name;

            reader.ReadStartElement(XD.Message11Dictionary.FaultCode, XD.Message11Dictionary.FaultNamespace);
            XmlUtil.ReadContentAsQName(reader, out name, out ns);
            FaultCode code = new FaultCode(name, ns);

            reader.ReadEndElement();

            string xmlLang = reader.XmlLang;

            reader.MoveToContent();  // Don't do IsStartElement.  FaultString is required, so let the reader throw.
            string          text        = reader.ReadElementContentAsString(XD.Message11Dictionary.FaultString.Value, XD.Message11Dictionary.FaultNamespace.Value);
            FaultReasonText translation = new FaultReasonText(text, xmlLang);

            string actor = "";

            if (reader.IsStartElement(XD.Message11Dictionary.FaultActor, XD.Message11Dictionary.FaultNamespace))
            {
                actor = reader.ReadElementContentAsString();
            }

            XmlBuffer detail = null;

            if (reader.IsStartElement(XD.Message11Dictionary.FaultDetail, XD.Message11Dictionary.FaultNamespace))
            {
                detail = new XmlBuffer(maxBufferSize);
                XmlDictionaryWriter writer = detail.OpenSection(reader.Quotas);
                writer.WriteNode(reader, false);
                detail.CloseSection();
                detail.Close();
            }
            reader.ReadEndElement();
            FaultReason reason = new FaultReason(translation);

            return(new ReceivedFault(code, reason, actor, actor, detail, EnvelopeVersion.Soap11));
        }
        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>
        /// Parses the "X509IssuerSerial" element and generates a corresponding <see cref="X509IssuerSerialKeyIdentifierClause"/> instance.
        /// </summary>
        /// <param name="dictionaryReader">The <see cref="XmlDictionaryReader"/> currently positioning on the "X509IssuerSerial" element. </param>
        /// <returns>An instance of <see cref="X509IssuerSerialKeyIdentifierClause"/> created from the "X509IssuerSerial" element.</returns>
        private static SecurityKeyIdentifierClause CreateIssuerSerialKeyIdentifierClause(XmlDictionaryReader dictionaryReader)
        {
            dictionaryReader.ReadStartElement(XmlSignatureConstants.Elements.X509IssuerSerial, XmlSignatureConstants.Namespace);

            if (!dictionaryReader.IsStartElement(XmlSignatureConstants.Elements.X509IssuerName, XmlSignatureConstants.Namespace))
            {
                throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3032, dictionaryReader.LocalName, dictionaryReader.NamespaceURI, XmlSignatureConstants.Elements.X509IssuerName, XmlSignatureConstants.Namespace));
            }

            string issuerName = dictionaryReader.ReadElementContentAsString(XmlSignatureConstants.Elements.X509IssuerName, XmlSignatureConstants.Namespace);

            if (!dictionaryReader.IsStartElement(XmlSignatureConstants.Elements.X509SerialNumber, XmlSignatureConstants.Namespace))
            {
                throw DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3032, dictionaryReader.LocalName, dictionaryReader.NamespaceURI, XmlSignatureConstants.Elements.X509SerialNumber, XmlSignatureConstants.Namespace));
            }

            string serialNumber = dictionaryReader.ReadElementContentAsString(XmlSignatureConstants.Elements.X509SerialNumber, XmlSignatureConstants.Namespace);

            dictionaryReader.ReadEndElement(); // Reade the ending </X509IssuerSerial> element.

            return(new X509IssuerSerialKeyIdentifierClause(issuerName, serialNumber));
        }
        public static MakeConnectionMessageInfo Create(XmlDictionaryReader reader)
        {
            MakeConnectionMessageInfo makeConnectionInfo = new MakeConnectionMessageInfo();

            if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.Name, MakeConnectionConstants.Namespace))
            {
                reader.ReadStartElement();
                reader.MoveToContent();

                while (reader.IsStartElement())
                {
                    if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.AddressElement, MakeConnectionConstants.Namespace))
                    {
                        if (!string.IsNullOrEmpty(makeConnectionInfo.Address))
                        {
                            makeConnectionInfo.MultipleAddressHeaders = true;
                            reader.Skip();
                        }
                        else
                        {
                            makeConnectionInfo.Address = reader.ReadElementContentAsString();
                        }
                    }
                    else if (reader.IsStartElement(MakeConnectionConstants.MakeConnectionMessage.IdentifierElement, MakeConnectionConstants.Namespace))
                    {
                        if (makeConnectionInfo.Identifier != null)
                        {
                            makeConnectionInfo.MultipleIdentifierHeaders = true;
                            reader.Skip();
                        }
                        else
                        {
                            makeConnectionInfo.Identifier = reader.ReadElementContentAsUniqueId();
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(makeConnectionInfo.UnknownSelection))
                        {
                            makeConnectionInfo.UnknownSelection = reader.LocalName;
                        }

                        reader.Skip();
                    }
                }

                reader.ReadEndElement();
            }

            return(makeConnectionInfo);
        }
Exemplo n.º 24
0
        public static Uri ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version, UriCache uriCache)
        {
            string uriString = reader.ReadElementContentAsString();

            if (uriString == version.Anonymous)
            {
                return(version.AnonymousUri);
            }
            if (uriCache == null)
            {
                return(new Uri(uriString));
            }
            return(uriCache.CreateUri(uriString));
        }
Exemplo n.º 25
0
        static MessageFault CreateFault11(Message message, int maxBufferSize)
        {
            FaultCode           fc      = null;
            FaultReason         fr      = null;
            object              details = null;
            XmlDictionaryReader r       = message.GetReaderAtBodyContents();

            r.ReadStartElement("Fault", message.Version.Envelope.Namespace);
            r.MoveToContent();

            while (r.NodeType != XmlNodeType.EndElement)
            {
                switch (r.LocalName)
                {
                case "faultcode":
                    fc = ReadFaultCode11(r);
                    break;

                case "faultstring":
                    fr = new FaultReason(r.ReadElementContentAsString());
                    break;

                case "detail":
                    //BUGBUG: Handle children of type other than ExceptionDetail, in order to comply with
                    //        FaultContractAttribute.
                    r.ReadStartElement();
                    r.MoveToContent();
                    details = new DataContractSerializer(typeof(ExceptionDetail)).ReadObject(r);
                    break;

                case "faultactor":
                default:
                    throw new NotImplementedException();
                }
                r.MoveToContent();
            }
            r.ReadEndElement();

            if (fr == null)
            {
                throw new XmlException("Reason is missing in the Fault message");
            }

            if (details == null)
            {
                return(CreateFault(fc, fr));
            }
            return(CreateFault(fc, fr, details));
        }
Exemplo n.º 26
0
        public virtual void ReadXml(XmlDictionaryReader reader,
                                    SamlSerializer samlSerializer,
                                    SecurityTokenSerializer keyInfoSerializer,
                                    SecurityTokenResolver resolver)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (samlSerializer == null)
            {
                throw new ArgumentNullException("samlSerializer");
            }
            references.Clear();
            assertions.Clear();

            reader.ReadStartElement("Evidence", SamlConstants.Namespace);
            for (reader.MoveToContent();
                 reader.NodeType == XmlNodeType.Element;
                 reader.MoveToContent())
            {
                if (reader.NamespaceURI != SamlConstants.Namespace)
                {
                    throw new SecurityTokenException(String.Format("Invalid SAML Evidence element: element '{0}' in namespace '{1}' is unexpected.", reader.LocalName, reader.NamespaceURI));
                }
                switch (reader.LocalName)
                {
                case "Assertion":
                    SamlAssertion a = new SamlAssertion();
                    a.ReadXml(reader, samlSerializer, keyInfoSerializer, resolver);
                    assertions.Add(a);
                    break;

                case "AssertionIDReference":
                    references.Add(reader.ReadElementContentAsString());
                    break;

                default:
                    throw new SecurityTokenException(String.Format("Invalid SAML Evidence element: SAML element '{0}' is unexpected.", reader.LocalName));
                }
            }
            reader.ReadEndElement();

            if (references.Count == 0 && assertions.Count == 0)
            {
                throw new SecurityTokenException("At least either one of AssertionIDReference or Assertion must exist in SAML Evidence.");
            }
        }