Beispiel #1
0
        internal static ContextMessageProperty ParseContextHeader(XmlReader reader)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            ContextMessageProperty result = new ContextMessageProperty();

            try
            {
                if (!reader.IsEmptyElement)
                {
                    reader.ReadStartElement(ContextHeaderName, ContextHeaderNamespace);

                    while (reader.MoveToContent() == XmlNodeType.Element)
                    {
                        if (reader.LocalName != ContextPropertyElement || reader.NamespaceURI != ContextHeaderNamespace)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      new ProtocolException(SR.GetString(SR.SchemaViolationInsideContextHeader)));
                        }

                        string propertyName = reader.GetAttribute(ContextPropertyNameAttribute);

                        if (string.IsNullOrEmpty(propertyName) || !ContextDictionary.TryValidateKeyValueSpace(propertyName))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                      new ProtocolException(SR.GetString(SR.InvalidCookieContent, propertyName)));
                        }
                        result.Context[propertyName] = reader.ReadElementString();
                    }

                    if (reader.NodeType != XmlNodeType.EndElement)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                  new ProtocolException(SR.GetString(SR.SchemaViolationInsideContextHeader)));
                    }
                }
            }
            catch (XmlException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ProtocolException(SR.GetString(SR.XmlFormatViolationInContextHeader), e));
            }

            return(result);
        }
        internal static ContextMessageProperty ParseContextHeader(XmlReader reader)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }
            ContextMessageProperty property = new ContextMessageProperty();

            try
            {
                if (reader.IsEmptyElement)
                {
                    return(property);
                }
                reader.ReadStartElement("Context", "http://schemas.microsoft.com/ws/2006/05/context");
                while (reader.MoveToContent() == XmlNodeType.Element)
                {
                    if ((reader.LocalName != "Property") || (reader.NamespaceURI != "http://schemas.microsoft.com/ws/2006/05/context"))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("SchemaViolationInsideContextHeader")));
                    }
                    string attribute = reader.GetAttribute("name");
                    if (string.IsNullOrEmpty(attribute) || !ContextDictionary.TryValidateKeyValueSpace(attribute))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("InvalidCookieContent", new object[] { attribute })));
                    }
                    property.Context[attribute] = reader.ReadElementString();
                }
                if (reader.NodeType != XmlNodeType.EndElement)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("SchemaViolationInsideContextHeader")));
                }
            }
            catch (XmlException exception)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("XmlFormatViolationInContextHeader"), exception));
            }
            return(property);
        }