Ejemplo n.º 1
0
        /// <summary>
        /// Parses the message XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void ParseMessageXml(EwsXmlReader reader)
        {
            // E12 and E14 return the MessageXml element in different
            // namespaces (types namespace for E12, errors namespace in E14). To
            // avoid this problem, the parser will match the namespace from the
            // start and end elements.
            XmlNamespace elementNS = EwsUtilities.GetNamespaceFromUri(reader.NamespaceUri);

            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();

                    if (reader.IsStartElement() && !reader.IsEmptyElement)
                    {
                        switch (reader.LocalName)
                        {
                        case XmlElementNames.Value:
                            this.errorDetails.Add(
                                reader.ReadAttributeValue(XmlAttributeNames.Name),
                                reader.ReadElementValue());
                            break;

                        default:
                            break;
                        }
                    }
                }while (!reader.IsEndElement(elementNS, XmlElementNames.MessageXml));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function that parses the RSTR from Windows Live and pulls out all the important pieces
        /// of data from it.
        /// </summary>
        /// <param name="rstResponse">The RSTR, positioned at the beginning of the SOAP body.</param>
        private void ParseWindowsLiveRSTResponseBody(EwsXmlReader rstResponse)
        {
            // Read the WS-Trust RequestSecurityTokenResponseCollection node.
            rstResponse.ReadStartElement(
                XmlNamespace.WSTrustFebruary2005,
                RequestSecurityTokenResponseCollectionElementName);

            // Skip the first token - our interest is in the second token (the service token).
            rstResponse.SkipElement(
                XmlNamespace.WSTrustFebruary2005,
                RequestSecurityTokenResponseElementName);

            // Now process the second token.
            rstResponse.ReadStartElement(
                XmlNamespace.WSTrustFebruary2005,
                RequestSecurityTokenResponseElementName);

            while (!rstResponse.IsEndElement(
                       XmlNamespace.WSTrustFebruary2005,
                       RequestSecurityTokenResponseElementName))
            {
                // Watch for the EncryptedData element - when we find it, parse out the appropriate bits of data.
                //
                // Also watch for the "pp" element in the Passport SOAP fault namespace, which indicates that
                // something went wrong with the token request.  If we find it, trace and throw accordingly.
                if (rstResponse.IsStartElement() &&
                    (rstResponse.LocalName == EncryptedDataElementName) &&
                    (rstResponse.NamespaceUri == XmlEncNamespace))
                {
                    this.SecurityToken = rstResponse.ReadOuterXml();
                }
                else if (rstResponse.IsStartElement(XmlNamespace.PassportSoapFault, PpElementName))
                {
                    if (this.TraceEnabled)
                    {
                        string logMessage = string.Format(
                            "Windows Live reported an error retrieving the token - {0}",
                            rstResponse.ReadOuterXml());
                        this.traceListener.Trace("WindowsLiveResponse", logMessage);
                    }
                    throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, EncryptedDataElementName));
                }

                // Move to the next bit of data...
                rstResponse.Read();
            }

            // If we didn't find the token, throw.
            if (this.SecurityToken == null)
            {
                if (this.TraceEnabled)
                {
                    string logMessage = string.Format(
                        "Did not find all required parts of the Windows Live response - " +
                        "Security Token - {0}",
                        (this.SecurityToken == null) ? "NOT FOUND" : "found");
                    this.traceListener.Trace("WindowsLiveResponse", logMessage);
                }
                throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, "No security token found."));
            }

            // Read past the RequestSecurityTokenResponseCollection end element.
            rstResponse.Read();
        }