public virtual XacmlContextRequest ReadContextRequest(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (!XacmlProtocolSerializer.CanReadContext(reader, XacmlConstants.ElementNames.Request, this.Version.NamespaceContext))
            {
                throw ThrowHelperXml(reader, "XML message is not valid.");
            }

            reader.ReadStartElement(XacmlConstants.ElementNames.Request, this.Version.NamespaceContext);

            List <XacmlContextSubject> subjects = new List <XacmlContextSubject>();

            this.ReadList(subjects, XacmlConstants.ElementNames.Subject, this.Version.NamespaceContext, ReadContextSubject, reader, isRequired: true);

            XacmlContextRequest result = new XacmlContextRequest(
                this.ReadRequired(XacmlConstants.ElementNames.Resource, this.Version.NamespaceContext, this.ReadContextResource, reader),
                this.ReadRequired(XacmlConstants.ElementNames.Action, this.Version.NamespaceContext, this.ReadContextAction, reader),
                subjects);

            result.Environment = this.ReadOptional(XacmlConstants.ElementNames.Environment, this.Version.NamespaceContext, this.ReadContextEnvironment, reader);

            reader.ReadEndElement();

            return(result);
        }
        public virtual XacmlContextResponse ReadContextResponse(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (!XacmlProtocolSerializer.CanReadContext(reader, XacmlConstants.ElementNames.Response, this.Version.NamespaceContext))
            {
                throw ThrowHelperXml(reader, "XML message is not valid.");
            }

            reader.ReadStartElement(XacmlConstants.ElementNames.Response, this.Version.NamespaceContext);

            List <XacmlContextResult> results = new List <XacmlContextResult>();

            this.ReadList(results, XacmlConstants.ElementNames.Result, this.Version.NamespaceContext, ReadContextResult, reader, isRequired: true);

            XacmlContextResponse result = new XacmlContextResponse(results);

            reader.ReadEndElement();

            return(result);
        }