/// <summary> /// Reads a single SOAP header. /// </summary> /// <param name="reader">EwsXmlReader</param> internal virtual void ReadSoapHeader(EwsXmlReader reader) { // Is this the ServerVersionInfo? if (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.ServerVersionInfo)) { this.service.ServerInfo = this.ReadServerVersionInfo(reader); } }
/// <summary> /// Read the partner token soap header. /// </summary> /// <param name="reader">EwsXmlReader</param> internal override void ReadSoapHeader(EwsXmlReader reader) { base.ReadSoapHeader(reader); if (this.expectPartnerToken) { if (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.PartnerToken)) { this.PartnerToken = reader.ReadInnerXml(); } if (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.PartnerTokenReference)) { this.PartnerTokenReference = reader.ReadInnerXml(); } } }
/// <summary> /// Loads the settings from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { reader.ReadStartElement(XmlNamespace.NotSpecified, XmlElementNames.Autodiscover); reader.ReadStartElement(XmlNamespace.NotSpecified, XmlElementNames.Response); do { reader.Read(); if (reader.IsStartElement()) { if (!this.TryReadCurrentXmlElement(reader)) { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Response)); reader.ReadEndElement(XmlNamespace.NotSpecified, XmlElementNames.Autodiscover); }
/// <summary> /// Loads the settings from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { reader.ReadStartElement(XmlNamespace.NotSpecified, XmlElementNames.Autodiscover); reader.ReadStartElement(XmlNamespace.NotSpecified, XmlElementNames.Response); do { reader.Read(); if (reader.IsStartElement()) { if (!this.TryReadCurrentXmlElement(reader)) { reader.SkipCurrentElement(); } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Response)); reader.ReadEndElement(XmlNamespace.NotSpecified, XmlElementNames.Autodiscover); }
/// <summary> /// Read ServerVersionInfo SOAP header. /// </summary> /// <param name="reader">EwsXmlReader</param> private ExchangeServerInfo ReadServerVersionInfo(EwsXmlReader reader) { ExchangeServerInfo serverInfo = new ExchangeServerInfo(); do { reader.Read(); if (reader.IsStartElement()) { switch (reader.LocalName) { case XmlElementNames.MajorVersion: serverInfo.MajorVersion = reader.ReadElementValue <int>(); break; case XmlElementNames.MinorVersion: serverInfo.MinorVersion = reader.ReadElementValue <int>(); break; case XmlElementNames.MajorBuildNumber: serverInfo.MajorBuildNumber = reader.ReadElementValue <int>(); break; case XmlElementNames.MinorBuildNumber: serverInfo.MinorBuildNumber = reader.ReadElementValue <int>(); break; case XmlElementNames.Version: serverInfo.VersionString = reader.ReadElementValue(); break; default: break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.ServerVersionInfo)); return(serverInfo); }
/// <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(); }
/// <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(); }
/// <summary> /// Reads the SOAP fault. /// </summary> /// <param name="reader">The reader.</param> /// <returns>SOAP fault details.</returns> private SoapFaultDetails ReadSoapFault(EwsXmlReader reader) { SoapFaultDetails soapFaultDetails = null; try { // WCF may not generate an XML declaration. reader.Read(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { reader.Read(); } if (!reader.IsStartElement() || (reader.LocalName != XmlElementNames.SOAPEnvelopeElementName)) { return(soapFaultDetails); } // Get the namespace URI from the envelope element and use it for the rest of the parsing. // If it's not 1.1 or 1.2, we can't continue. XmlNamespace soapNamespace = EwsUtilities.GetNamespaceFromUri(reader.NamespaceUri); if (soapNamespace == XmlNamespace.NotSpecified) { return(soapFaultDetails); } reader.Read(); // Skip SOAP header. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.Read(); }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); // Queue up the next read reader.Read(); } // Parse the fault element contained within the SOAP body. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.Read(); // Parse Fault element if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPFaultElementName)) { soapFaultDetails = SoapFaultDetails.Parse(reader, soapNamespace); } }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPBodyElementName)); } reader.ReadEndElement(soapNamespace, XmlElementNames.SOAPEnvelopeElementName); } catch (XmlException) { // If response doesn't contain a valid SOAP fault, just ignore exception and // return null for SOAP fault details. } return(soapFaultDetails); }
/// <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)); } }
/// <summary> /// Read ServerVersionInfo SOAP header. /// </summary> /// <param name="reader">EwsXmlReader</param> private ExchangeServerInfo ReadServerVersionInfo(EwsXmlReader reader) { ExchangeServerInfo serverInfo = new ExchangeServerInfo(); do { reader.Read(); if (reader.IsStartElement()) { switch (reader.LocalName) { case XmlElementNames.MajorVersion: serverInfo.MajorVersion = reader.ReadElementValue<int>(); break; case XmlElementNames.MinorVersion: serverInfo.MinorVersion = reader.ReadElementValue<int>(); break; case XmlElementNames.MajorBuildNumber: serverInfo.MajorBuildNumber = reader.ReadElementValue<int>(); break; case XmlElementNames.MinorBuildNumber: serverInfo.MinorBuildNumber = reader.ReadElementValue<int>(); break; case XmlElementNames.Version: serverInfo.VersionString = reader.ReadElementValue(); break; default: break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.ServerVersionInfo)); return serverInfo; }
/// <summary> /// Reads a single SOAP header. /// </summary> /// <param name="reader">EwsXmlReader</param> internal virtual void ReadSoapHeader(EwsXmlReader reader) { // Is this the ServerVersionInfo? if (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.ServerVersionInfo)) { this.service.ServerInfo = this.ReadServerVersionInfo(reader); } }
/// <summary> /// Reads the SOAP fault. /// </summary> /// <param name="reader">The reader.</param> /// <returns>SOAP fault details.</returns> private SoapFaultDetails ReadSoapFault(EwsXmlReader reader) { SoapFaultDetails soapFaultDetails = null; try { // WCF may not generate an XML declaration. reader.Read(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { reader.Read(); } if (!reader.IsStartElement() || (reader.LocalName != XmlElementNames.SOAPEnvelopeElementName)) { return soapFaultDetails; } // Get the namespace URI from the envelope element and use it for the rest of the parsing. // If it's not 1.1 or 1.2, we can't continue. XmlNamespace soapNamespace = EwsUtilities.GetNamespaceFromUri(reader.NamespaceUri); if (soapNamespace == XmlNamespace.NotSpecified) { return soapFaultDetails; } reader.Read(); // Skip SOAP header. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.Read(); } while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); // Queue up the next read reader.Read(); } // Parse the fault element contained within the SOAP body. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.Read(); // Parse Fault element if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPFaultElementName)) { soapFaultDetails = SoapFaultDetails.Parse(reader, soapNamespace); } } while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPBodyElementName)); } reader.ReadEndElement(soapNamespace, XmlElementNames.SOAPEnvelopeElementName); } catch (XmlException) { // If response doesn't contain a valid SOAP fault, just ignore exception and // return null for SOAP fault details. } return soapFaultDetails; }
/// <summary> /// Loads DocumentSharingLocation instance from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>DocumentSharingLocation.</returns> internal static DocumentSharingLocation LoadFromXml(EwsXmlReader reader) { DocumentSharingLocation location = new DocumentSharingLocation(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.ServiceUrl: location.ServiceUrl = reader.ReadElementValue<string>(); break; case XmlElementNames.LocationUrl: location.LocationUrl = reader.ReadElementValue<string>(); break; case XmlElementNames.DisplayName: location.DisplayName = reader.ReadElementValue<string>(); break; case XmlElementNames.SupportedFileExtensions: List<string> fileExtensions = new List<string>(); reader.Read(); while (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.FileExtension)) { string extension = reader.ReadElementValue<string>(); fileExtensions.Add(extension); reader.Read(); } location.SupportedFileExtensions = fileExtensions; break; case XmlElementNames.ExternalAccessAllowed: location.ExternalAccessAllowed = reader.ReadElementValue<bool>(); break; case XmlElementNames.AnonymousAccessAllowed: location.AnonymousAccessAllowed = reader.ReadElementValue<bool>(); break; case XmlElementNames.CanModifyPermissions: location.CanModifyPermissions = reader.ReadElementValue<bool>(); break; case XmlElementNames.IsDefault: location.IsDefault = reader.ReadElementValue<bool>(); break; default: break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DocumentSharingLocation)); return location; }
/// <summary> /// Read the partner token soap header. /// </summary> /// <param name="reader">EwsXmlReader</param> internal override void ReadSoapHeader(EwsXmlReader reader) { base.ReadSoapHeader(reader); if (this.expectPartnerToken) { if (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.PartnerToken)) { this.PartnerToken = reader.ReadInnerXml(); } if (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.PartnerTokenReference)) { this.PartnerTokenReference = reader.ReadInnerXml(); } } }
/// <summary> /// Loads DocumentSharingLocation instance from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>DocumentSharingLocation.</returns> internal static DocumentSharingLocation LoadFromXml(EwsXmlReader reader) { DocumentSharingLocation location = new DocumentSharingLocation(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.ServiceUrl: location.ServiceUrl = reader.ReadElementValue <string>(); break; case XmlElementNames.LocationUrl: location.LocationUrl = reader.ReadElementValue <string>(); break; case XmlElementNames.DisplayName: location.DisplayName = reader.ReadElementValue <string>(); break; case XmlElementNames.SupportedFileExtensions: List <string> fileExtensions = new List <string>(); reader.Read(); while (reader.IsStartElement(XmlNamespace.Autodiscover, XmlElementNames.FileExtension)) { string extension = reader.ReadElementValue <string>(); fileExtensions.Add(extension); reader.Read(); } location.SupportedFileExtensions = fileExtensions; break; case XmlElementNames.ExternalAccessAllowed: location.ExternalAccessAllowed = reader.ReadElementValue <bool>(); break; case XmlElementNames.AnonymousAccessAllowed: location.AnonymousAccessAllowed = reader.ReadElementValue <bool>(); break; case XmlElementNames.CanModifyPermissions: location.CanModifyPermissions = reader.ReadElementValue <bool>(); break; case XmlElementNames.IsDefault: location.IsDefault = reader.ReadElementValue <bool>(); break; default: break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DocumentSharingLocation)); return(location); }