/// <summary> /// Loads response from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="endElementName">End element name.</param> internal override void LoadFromXml(EwsXmlReader reader, string endElementName) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.RedirectTarget: this.RedirectTarget = reader.ReadElementValue(); break; case XmlElementNames.UserSettingErrors: this.LoadUserSettingErrorsFromXml(reader); break; case XmlElementNames.UserSettings: this.LoadUserSettingsFromXml(reader); break; default: base.LoadFromXml(reader, endElementName); break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, endElementName)); }
/// <summary> /// Loads WebClientUrl instance from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>WebClientUrl.</returns> internal static WebClientUrl LoadFromXml(EwsXmlReader reader) { WebClientUrl webClientUrl = new WebClientUrl(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.AuthenticationMethods: webClientUrl.AuthenticationMethods = reader.ReadElementValue<string>(); break; case XmlElementNames.Url: webClientUrl.Url = reader.ReadElementValue<string>(); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.WebClientUrl)); return webClientUrl; }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.ErrorCode: this.errorCode = reader.ReadElementValue <AutodiscoverErrorCode>(); break; case XmlElementNames.ErrorMessage: this.errorMessage = reader.ReadElementValue(); break; case XmlElementNames.SettingName: this.settingName = reader.ReadElementValue(); break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSettingError)); }
/// <summary> /// Read user setting with ProtocolConnectionCollection value. /// </summary> /// <param name="reader">EwsServiceXmlReader</param> internal static ProtocolConnectionCollection LoadFromXml(EwsXmlReader reader) { ProtocolConnectionCollection value = new ProtocolConnectionCollection(); ProtocolConnection connection = null; do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == XmlElementNames.ProtocolConnection) { connection = ProtocolConnection.LoadFromXml(reader); if (connection != null) { value.Connections.Add(connection); } } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.ProtocolConnections)); return value; }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadDomainSettingsFromXml(EwsXmlReader reader) { if (!reader.IsEmptyElement) { do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.DomainSetting)) { string settingClass = reader.ReadAttributeValue(XmlNamespace.XmlSchemaInstance, XmlAttributeNames.Type); switch (settingClass) { case XmlElementNames.DomainStringSetting: this.ReadSettingFromXml(reader); break; default: EwsUtilities.Assert( false, "GetDomainSettingsResponse.LoadDomainSettingsFromXml", string.Format("Invalid setting class '{0}' returned", settingClass)); break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSettings)); } }
/// <summary> /// Reads domain setting from XML. /// </summary> /// <param name="reader">The reader.</param> private void ReadSettingFromXml(EwsXmlReader reader) { DomainSettingName?name = null; object value = null; do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Name: name = reader.ReadElementValue <DomainSettingName>(); break; case XmlElementNames.Value: value = reader.ReadElementValue(); break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSetting)); EwsUtilities.Assert( name.HasValue, "GetDomainSettingsResponse.ReadSettingFromXml", "Missing name element in domain setting"); this.settings.Add(name.Value, value); }
/// <summary> /// Load from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.DisplayName: this.displayName = reader.ReadElementValue(); break; case XmlElementNames.LegacyDN: this.legacyDN = reader.ReadElementValue(); break; case XmlElementNames.DeploymentId: this.deploymentId = reader.ReadElementValue(); break; case XmlElementNames.AutoDiscoverSMTPAddress: this.autodiscoverAMTPAddress = reader.ReadElementValue(); break; default: reader.SkipCurrentElement(); break; } } }while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.User)); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadUserSettingsFromXml(EwsXmlReader reader) { if (!reader.IsEmptyElement) { do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.UserSetting)) { string settingClass = reader.ReadAttributeValue(XmlNamespace.XmlSchemaInstance, XmlAttributeNames.Type); switch (settingClass) { case XmlElementNames.StringSetting: case XmlElementNames.WebClientUrlCollectionSetting: case XmlElementNames.AlternateMailboxCollectionSetting: case XmlElementNames.ProtocolConnectionCollectionSetting: case XmlElementNames.DocumentSharingLocationCollectionSetting: this.ReadSettingFromXml(reader); break; default: EwsUtilities.Assert( false, "GetUserSettingsResponse.LoadUserSettingsFromXml", string.Format("Invalid setting class '{0}' returned", settingClass)); break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.UserSettings)); } }
/// <summary> /// Reads user setting from XML. /// </summary> /// <param name="reader">The reader.</param> private void ReadSettingFromXml(EwsXmlReader reader) { string name = null; object value = null; do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Name: name = reader.ReadElementValue <string>(); break; case XmlElementNames.Value: value = reader.ReadElementValue(); break; case XmlElementNames.WebClientUrls: value = WebClientUrlCollection.LoadFromXml(reader); break; case XmlElementNames.ProtocolConnections: value = ProtocolConnectionCollection.LoadFromXml(reader); break; case XmlElementNames.AlternateMailboxes: value = AlternateMailboxCollection.LoadFromXml(reader); break; case XmlElementNames.DocumentSharingLocations: value = DocumentSharingLocationCollection.LoadFromXml(reader); break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.UserSetting)); // EWS Managed API is broken with AutoDSvc endpoint in RedirectUrl scenario try { UserSettingName userSettingName = EwsUtilities.Parse <UserSettingName>(name); this.Settings.Add(userSettingName, value); } catch (ArgumentException) { // ignore unexpected UserSettingName in the response (due to the server-side bugs). // it'd be better if this is hooked into ITraceListener, but that is unavailable here. // // in case "name" is null, EwsUtilities.Parse throws ArgumentNullException // (which derives from ArgumentException). // EwsUtilities.Assert( false, "GetUserSettingsResponse.ReadSettingFromXml", "Unexpected or empty name element in user setting"); } }
/// <summary> /// Read user setting with ProtocolConnection value. /// </summary> /// <param name="reader">EwsServiceXmlReader</param> internal static ProtocolConnection LoadFromXml(EwsXmlReader reader) { ProtocolConnection connection = new ProtocolConnection(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.EncryptionMethod: connection.EncryptionMethod = reader.ReadElementValue<string>(); break; case XmlElementNames.Hostname: connection.Hostname = reader.ReadElementValue<string>(); break; case XmlElementNames.Port: connection.Port = reader.ReadElementValue<int>(); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.ProtocolConnection)); return connection; }
/// <summary> /// Loads WebClientUrl instance from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>WebClientUrl.</returns> internal static WebClientUrl LoadFromXml(EwsXmlReader reader) { WebClientUrl webClientUrl = new WebClientUrl(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.AuthenticationMethods: webClientUrl.AuthenticationMethods = reader.ReadElementValue<string>(); break; case XmlElementNames.Url: webClientUrl.Url = reader.ReadElementValue<string>(); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.WebClientUrl)); return webClientUrl; }
/// <summary> /// Read SOAP headers. /// </summary> /// <param name="reader">EwsXmlReader</param> internal void ReadSoapHeaders(EwsXmlReader reader) { reader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPHeaderElementName); do { reader.Read(); this.ReadSoapHeader(reader); }while (!reader.IsEndElement(XmlNamespace.Soap, XmlElementNames.SOAPHeaderElementName)); }
/// <summary> /// Loads instance of AlternateMailboxCollection from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>AlternateMailboxCollection</returns> internal static AlternateMailboxCollection LoadFromXml(EwsXmlReader reader) { AlternateMailboxCollection instance = new AlternateMailboxCollection(); do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.AlternateMailbox)) { instance.Entries.Add(AlternateMailbox.LoadFromXml(reader)); } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.AlternateMailboxes)); return(instance); }
/// <summary> /// Loads instance of WebClientUrlCollection from XML. /// </summary> /// <param name="reader">The reader.</param> internal static WebClientUrlCollection LoadFromXml(EwsXmlReader reader) { WebClientUrlCollection instance = new WebClientUrlCollection(); do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.WebClientUrl)) { instance.Urls.Add(WebClientUrl.LoadFromXml(reader)); } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.WebClientUrls)); return(instance); }
/// <summary> /// Loads the response collection from XML. /// </summary> /// <param name="reader">The reader.</param> private void LoadResponseCollectionFromXml(EwsXmlReader reader) { if (!reader.IsEmptyElement) { do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == this.GetResponseInstanceXmlElementName())) { TResponse response = this.CreateResponseInstance(); response.LoadFromXml(reader, this.GetResponseInstanceXmlElementName()); this.Responses.Add(response); } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, this.GetResponseCollectionXmlElementName())); } }
/// <summary> /// Loads instance of AlternateMailboxCollection from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>AlternateMailboxCollection</returns> internal static AlternateMailboxCollection LoadFromXml(EwsXmlReader reader) { AlternateMailboxCollection instance = new AlternateMailboxCollection(); do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.AlternateMailbox)) { instance.Entries.Add(AlternateMailbox.LoadFromXml(reader)); } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.AlternateMailboxes)); return instance; }
/// <summary> /// Loads instance of WebClientUrlCollection from XML. /// </summary> /// <param name="reader">The reader.</param> internal static WebClientUrlCollection LoadFromXml(EwsXmlReader reader) { WebClientUrlCollection instance = new WebClientUrlCollection(); do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.WebClientUrl)) { instance.Urls.Add(WebClientUrl.LoadFromXml(reader)); } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.WebClientUrls)); return instance; }
/// <summary> /// Loads instance of DocumentSharingLocationCollection from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>DocumentSharingLocationCollection</returns> internal static DocumentSharingLocationCollection LoadFromXml(EwsXmlReader reader) { DocumentSharingLocationCollection instance = new DocumentSharingLocationCollection(); do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.DocumentSharingLocation)) { DocumentSharingLocation location = DocumentSharingLocation.LoadFromXml(reader); instance.Entries.Add(location); } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DocumentSharingLocations)); return(instance); }
/// <summary> /// Loads the user setting errors. /// </summary> /// <param name="reader">The reader.</param> private void LoadUserSettingErrorsFromXml(EwsXmlReader reader) { if (!reader.IsEmptyElement) { do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.UserSettingError)) { UserSettingError error = new UserSettingError(); error.LoadFromXml(reader); this.UserSettingErrors.Add(error); } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.UserSettingErrors)); } }
/// <summary> /// Loads instance of DocumentSharingLocationCollection from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>DocumentSharingLocationCollection</returns> internal static DocumentSharingLocationCollection LoadFromXml(EwsXmlReader reader) { DocumentSharingLocationCollection instance = new DocumentSharingLocationCollection(); do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.DocumentSharingLocation)) { DocumentSharingLocation location = DocumentSharingLocation.LoadFromXml(reader); instance.Entries.Add(location); } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DocumentSharingLocations)); return instance; }
/// <summary> /// Loads AlternateMailbox instance from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>AlternateMailbox.</returns> internal static AlternateMailbox LoadFromXml(EwsXmlReader reader) { AlternateMailbox altMailbox = new AlternateMailbox(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Type: altMailbox.Type = reader.ReadElementValue <string>(); break; case XmlElementNames.DisplayName: altMailbox.DisplayName = reader.ReadElementValue <string>(); break; case XmlElementNames.LegacyDN: altMailbox.LegacyDN = reader.ReadElementValue <string>(); break; case XmlElementNames.Server: altMailbox.Server = reader.ReadElementValue <string>(); break; case XmlElementNames.SmtpAddress: altMailbox.SmtpAddress = reader.ReadElementValue <string>(); break; case XmlElementNames.OwnerSmtpAddress: altMailbox.OwnerSmtpAddress = reader.ReadElementValue <string>(); break; default: break; } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.AlternateMailbox)); return(altMailbox); }
/// <summary> /// Loads response from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="endElementName">End element name.</param> internal override void LoadFromXml(EwsXmlReader reader, string endElementName) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == this.GetResponseCollectionXmlElementName()) { this.LoadResponseCollectionFromXml(reader); } else { base.LoadFromXml(reader, endElementName); } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, endElementName)); }
/// <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> /// Loads web client urls from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="webClientUrls">The web client urls.</param> /// <param name="elementName">Name of the element.</param> private static void LoadWebClientUrlsFromXml(EwsXmlReader reader, WebClientUrlCollection webClientUrls, string elementName) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.OWAUrl: string authMethod = reader.ReadAttributeValue(XmlAttributeNames.AuthenticationMethod); string owaUrl = reader.ReadElementValue(); WebClientUrl webClientUrl = new WebClientUrl(authMethod, owaUrl); webClientUrls.Urls.Add(webClientUrl); break; default: reader.SkipCurrentElement(); break; } } }while (!reader.IsEndElement(XmlNamespace.NotSpecified, elementName)); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.ErrorCode: this.errorCode = reader.ReadElementValue<AutodiscoverErrorCode>(); break; case XmlElementNames.ErrorMessage: this.errorMessage = reader.ReadElementValue(); break; case XmlElementNames.SettingName: this.settingName = reader.ReadElementValue(); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSettingError)); }
/// <summary> /// Parses the XML through the specified reader and creates an Autodiscover error. /// </summary> /// <param name="reader">The reader.</param> /// <returns>An Autodiscover error.</returns> internal static AutodiscoverError Parse(EwsXmlReader reader) { AutodiscoverError error = new AutodiscoverError(); error.time = reader.ReadAttributeValue(XmlAttributeNames.Time); error.id = reader.ReadAttributeValue(XmlAttributeNames.Id); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.ErrorCode: error.errorCode = reader.ReadElementValue <int>(); break; case XmlElementNames.Message: error.message = reader.ReadElementValue(); break; case XmlElementNames.DebugData: error.debugData = reader.ReadElementValue(); break; default: reader.SkipCurrentElement(); break; } } }while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Error)); return(error); }
/// <summary> /// Read user setting with ProtocolConnectionCollection value. /// </summary> /// <param name="reader">EwsServiceXmlReader</param> internal static ProtocolConnectionCollection LoadFromXml(EwsXmlReader reader) { ProtocolConnectionCollection value = new ProtocolConnectionCollection(); ProtocolConnection connection = null; do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == XmlElementNames.ProtocolConnection) { connection = ProtocolConnection.LoadFromXml(reader); if (connection != null) { value.Connections.Add(connection); } } } }while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.ProtocolConnections)); return(value); }
/// <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> /// Load from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.DisplayName: this.displayName = reader.ReadElementValue(); break; case XmlElementNames.LegacyDN: this.legacyDN = reader.ReadElementValue(); break; case XmlElementNames.DeploymentId: this.deploymentId = reader.ReadElementValue(); break; case XmlElementNames.AutoDiscoverSMTPAddress: this.autodiscoverAMTPAddress = reader.ReadElementValue(); break; default: reader.SkipCurrentElement(); break; } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.User)); }
/// <summary> /// Function that parses the SOAP headers from the response to the RST to Windows Live. /// </summary> /// <param name="rstResponse">The Windows Live response, positioned at the beginning of the SOAP headers.</param> private void ReadWindowsLiveRSTResponseHeaders(EwsXmlReader rstResponse) { // Read the beginning of the SOAP header, then go looking for the Passport SOAP fault section... rstResponse.ReadStartElement( WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPHeaderElementName); // Attempt to read to the psf:pp element - if at the end of the ReadToDescendant call we're at the // end element for the SOAP headers, we didn't find it. rstResponse.ReadToDescendant(XmlNamespace.PassportSoapFault, PpElementName); if (rstResponse.IsEndElement(WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPHeaderElementName)) { // We didn't find the psf:pp element - without that, we don't know what happened - // something went wrong. Trace and throw. if (this.TraceEnabled) { this.traceListener.Trace( "WindowsLiveResponse", "Could not find Passport SOAP fault information in Windows Live response"); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, PpElementName)); } // Now that we've found the psf:pp element, look for the 'reqstatus' element under it. If after // the ReadToDescendant call we're at the end element for the psf:pp element, we didn't find it. rstResponse.ReadToDescendant(XmlNamespace.PassportSoapFault, ReqstatusElementName); if (rstResponse.IsEndElement(XmlNamespace.PassportSoapFault, PpElementName)) { // We didn't find the "reqstatus" element - without that, we don't know what happened - // something went wrong. Trace and throw. if (this.TraceEnabled) { this.traceListener.Trace( "WindowsLiveResponse", "Could not find reqstatus element in Passport SOAP fault information in Windows Live response"); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, ReqstatusElementName)); } // Now that we've found the reqstatus element, get its value. string reqstatus = rstResponse.ReadElementValue(); // Read to body tag in both success and failure cases, // since we need to trace the fault response in failure cases while (!rstResponse.IsEndElement(WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPHeaderElementName)) { rstResponse.Read(); } if (!string.Equals(reqstatus, SuccessfulReqstatus)) { // Our request status was non-zero - something went wrong. Trace and throw. if (this.TraceEnabled) { string logMessage = string.Format( "Received status {0} from Windows Live instead of {1}.", reqstatus, SuccessfulReqstatus); this.traceListener.Trace("WindowsLiveResponse", logMessage); rstResponse.ReadStartElement( WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPBodyElementName); // Trace Fault Information this.traceListener.Trace( "WindowsLiveResponse", string.Format( "Windows Live reported Fault : {0}", rstResponse.ReadInnerXml())); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, ReqstatusElementName + ": " + reqstatus)); } }
/// <summary> /// Reads domain setting from XML. /// </summary> /// <param name="reader">The reader.</param> private void ReadSettingFromXml(EwsXmlReader reader) { DomainSettingName? name = null; object value = null; do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Name: name = reader.ReadElementValue<DomainSettingName>(); break; case XmlElementNames.Value: value = reader.ReadElementValue(); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSetting)); EwsUtilities.Assert( name.HasValue, "GetDomainSettingsResponse.ReadSettingFromXml", "Missing name element in domain setting"); this.settings.Add(name.Value, value); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadDomainSettingsFromXml(EwsXmlReader reader) { if (!reader.IsEmptyElement) { do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.DomainSetting)) { string settingClass = reader.ReadAttributeValue(XmlNamespace.XmlSchemaInstance, XmlAttributeNames.Type); switch (settingClass) { case XmlElementNames.DomainStringSetting: this.ReadSettingFromXml(reader); break; default: EwsUtilities.Assert( false, "GetDomainSettingsResponse.LoadDomainSettingsFromXml", string.Format("Invalid setting class '{0}' returned", settingClass)); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSettings)); } }
/// <summary> /// Parses the detail node. /// </summary> /// <param name="reader">The reader.</param> private void ParseDetailNode(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.EwsResponseCodeElementName: try { this.ResponseCode = reader.ReadElementValue<ServiceError>(); } catch (ArgumentException) { // ServiceError couldn't be mapped to enum value, treat as an ISE this.ResponseCode = ServiceError.ErrorInternalServerError; } break; case XmlElementNames.EwsMessageElementName: this.Message = reader.ReadElementValue(); break; case XmlElementNames.EwsLineElementName: this.LineNumber = reader.ReadElementValue<int>(); break; case XmlElementNames.EwsPositionElementName: this.PositionWithinLine = reader.ReadElementValue<int>(); break; case XmlElementNames.EwsErrorCodeElementName: try { this.ErrorCode = reader.ReadElementValue<ServiceError>(); } catch (ArgumentException) { // ServiceError couldn't be mapped to enum value, treat as an ISE this.ErrorCode = ServiceError.ErrorInternalServerError; } break; case XmlElementNames.EwsExceptionTypeElementName: this.ExceptionType = reader.ReadElementValue(); break; case XmlElementNames.MessageXml: this.ParseMessageXml(reader); break; default: // Ignore any other details break; } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.SOAPDetailElementName)); }
/// <summary> /// Loads response from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="endElementName">End element name.</param> internal override void LoadFromXml(EwsXmlReader reader, string endElementName) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.RedirectTarget: this.redirectTarget = reader.ReadElementValue(); break; case XmlElementNames.DomainSettingErrors: this.LoadDomainSettingErrorsFromXml(reader); break; case XmlElementNames.DomainSettings: this.LoadDomainSettingsFromXml(reader); break; default: base.LoadFromXml(reader, endElementName); break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, endElementName)); }
/// <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> /// Load from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.AccountType: this.AccountType = reader.ReadElementValue(); break; case XmlElementNames.Action: string xmlResponseType = reader.ReadElementValue(); switch (xmlResponseType) { case OutlookAccount.Settings: this.ResponseType = AutodiscoverResponseType.Success; break; case OutlookAccount.RedirectUrl: this.ResponseType = AutodiscoverResponseType.RedirectUrl; break; case OutlookAccount.RedirectAddr: this.ResponseType = AutodiscoverResponseType.RedirectAddress; break; default: this.ResponseType = AutodiscoverResponseType.Error; break; } break; case XmlElementNames.Protocol: OutlookProtocol protocol = new OutlookProtocol(); protocol.LoadFromXml(reader); if (this.protocols.ContainsKey(protocol.ProtocolType)) { // There should be strictly one node per protocol type in the autodiscover response. throw new ServiceLocalException(Strings.InvalidAutodiscoverServiceResponse); } this.protocols.Add(protocol.ProtocolType, protocol); break; case XmlElementNames.RedirectAddr: case XmlElementNames.RedirectUrl: this.RedirectTarget = reader.ReadElementValue(); break; case XmlElementNames.AlternateMailboxes: AlternateMailbox alternateMailbox = AlternateMailbox.LoadFromXml(reader); this.alternateMailboxes.Entries.Add(alternateMailbox); break; default: reader.SkipCurrentElement(); break; } } }while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Account)); }
/// <summary> /// Loads web client urls from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="webClientUrls">The web client urls.</param> /// <param name="elementName">Name of the element.</param> private static void LoadWebClientUrlsFromXml(EwsXmlReader reader, WebClientUrlCollection webClientUrls, string elementName) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.OWAUrl: string authMethod = reader.ReadAttributeValue(XmlAttributeNames.AuthenticationMethod); string owaUrl = reader.ReadElementValue(); WebClientUrl webClientUrl = new WebClientUrl(authMethod, owaUrl); webClientUrls.Urls.Add(webClientUrl); break; default: reader.SkipCurrentElement(); break; } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, elementName)); }
/// <summary> /// Function that parses the SOAP headers from the response to the RST to Windows Live. /// </summary> /// <param name="rstResponse">The Windows Live response, positioned at the beginning of the SOAP headers.</param> /* private */ void ReadWindowsLiveRSTResponseHeaders(EwsXmlReader rstResponse) { // Read the beginning of the SOAP header, then go looking for the Passport SOAP fault section... rstResponse.ReadStartElement( WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPHeaderElementName); // Attempt to read to the psf:pp element - if at the end of the ReadToDescendant call we're at the // end element for the SOAP headers, we didn't find it. rstResponse.ReadToDescendant(XmlNamespace.PassportSoapFault, PpElementName); if (rstResponse.IsEndElement(WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPHeaderElementName)) { // We didn't find the psf:pp element - without that, we don't know what happened - // something went wrong. Trace and throw. if (this.TraceEnabled) { this.traceListener.Trace( "WindowsLiveResponse", "Could not find Passport SOAP fault information in Windows Live response"); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, PpElementName)); } // Now that we've found the psf:pp element, look for the 'reqstatus' element under it. If after // the ReadToDescendant call we're at the end element for the psf:pp element, we didn't find it. rstResponse.ReadToDescendant(XmlNamespace.PassportSoapFault, ReqstatusElementName); if (rstResponse.IsEndElement(XmlNamespace.PassportSoapFault, PpElementName)) { // We didn't find the "reqstatus" element - without that, we don't know what happened - // something went wrong. Trace and throw. if (this.TraceEnabled) { this.traceListener.Trace( "WindowsLiveResponse", "Could not find reqstatus element in Passport SOAP fault information in Windows Live response"); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, ReqstatusElementName)); } // Now that we've found the reqstatus element, get its value. String reqstatus = rstResponse.ReadElementValue(); // Read to body tag in both success and failure cases, // since we need to trace the fault response in failure cases while (!rstResponse.IsEndElement(WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPHeaderElementName)) { rstResponse.Read(); } if (!string.Equals(reqstatus, SuccessfulReqstatus)) { // Our request status was non-zero - something went wrong. Trace and throw. if (this.TraceEnabled) { String logMessage = string.Format( "Received status {0} from Windows Live instead of {1}.", reqstatus, SuccessfulReqstatus); this.traceListener.Trace("WindowsLiveResponse", logMessage); rstResponse.ReadStartElement( WindowsLiveSoapNamespacePrefix, XmlElementNames.SOAPBodyElementName); // Trace Fault Information this.traceListener.Trace( "WindowsLiveResponse", string.Format( "Windows Live reported Fault : {0}", rstResponse.ReadInnerXml())); } throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, ReqstatusElementName + ": " + reqstatus)); } }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Type: this.ProtocolType = OutlookProtocol.ProtocolNameToType(reader.ReadElementValue()); break; case XmlElementNames.AuthPackage: this.authPackage = reader.ReadElementValue(); break; case XmlElementNames.Server: this.server = reader.ReadElementValue(); break; case XmlElementNames.ServerDN: this.serverDN = reader.ReadElementValue(); break; case XmlElementNames.ServerVersion: // just read it out reader.ReadElementValue(); break; case XmlElementNames.AD: this.activeDirectoryServer = reader.ReadElementValue(); break; case XmlElementNames.MdbDN: this.mailboxDN = reader.ReadElementValue(); break; case XmlElementNames.EWSUrl: this.exchangeWebServicesUrl = reader.ReadElementValue(); break; case XmlElementNames.EmwsUrl: this.exchangeManagementWebServicesUrl = reader.ReadElementValue(); break; case XmlElementNames.ASUrl: this.availabilityServiceUrl = reader.ReadElementValue(); break; case XmlElementNames.OOFUrl: // just read it out reader.ReadElementValue(); break; case XmlElementNames.UMUrl: this.unifiedMessagingUrl = reader.ReadElementValue(); break; case XmlElementNames.OABUrl: this.offlineAddressBookUrl = reader.ReadElementValue(); break; case XmlElementNames.PublicFolderServer: this.publicFolderServer = reader.ReadElementValue(); break; case XmlElementNames.Internal: OutlookProtocol.LoadWebClientUrlsFromXml(reader, this.internalOutlookWebAccessUrls, reader.LocalName); break; case XmlElementNames.External: OutlookProtocol.LoadWebClientUrlsFromXml(reader, this.externalOutlookWebAccessUrls, reader.LocalName); break; case XmlElementNames.Ssl: string sslStr = reader.ReadElementValue(); this.sslEnabled = sslStr.Equals("On", StringComparison.OrdinalIgnoreCase); break; case XmlElementNames.SharingUrl: this.sharingEnabled = reader.ReadElementValue().Length > 0; break; case XmlElementNames.EcpUrl: this.ecpUrl = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_um: this.ecpUrlUm = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_aggr: this.ecpUrlAggr = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_sms: this.ecpUrlSms = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_mt: this.ecpUrlMt = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_ret: this.ecpUrlRet = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_publish: this.ecpUrlPublish = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_photo: this.ecpUrlPhoto = reader.ReadElementValue(); break; case XmlElementNames.ExchangeRpcUrl: this.exchangeRpcUrl = reader.ReadElementValue(); break; case XmlElementNames.EwsPartnerUrl: this.exchangeWebServicesPartnerUrl = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_connect: this.ecpUrlConnect = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tm: this.ecpUrlTm = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tmCreating: this.ecpUrlTmCreating = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tmEditing: this.ecpUrlTmEditing = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tmHiding: this.ecpUrlTmHiding = reader.ReadElementValue(); break; case XmlElementNames.SiteMailboxCreationURL: this.siteMailboxCreationURL = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_extinstall: this.ecpUrlExtInstall = reader.ReadElementValue(); break; case XmlElementNames.ServerExclusiveConnect: string serverExclusiveConnectStr = reader.ReadElementValue(); this.serverExclusiveConnect = serverExclusiveConnectStr.Equals("On", StringComparison.OrdinalIgnoreCase); break; case XmlElementNames.CertPrincipalName: this.certPrincipalName = reader.ReadElementValue(); break; case XmlElementNames.GroupingInformation: this.groupingInformation = reader.ReadElementValue(); break; default: reader.SkipCurrentElement(); break; } } }while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Protocol)); }
/// <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 soap:Fault content. /// </summary> /// <param name="reader">The reader.</param> /// <param name="soapNamespace">The SOAP namespace to use.</param> /// <returns>SOAP fault details.</returns> internal static SoapFaultDetails Parse(EwsXmlReader reader, XmlNamespace soapNamespace) { SoapFaultDetails soapFaultDetails = new SoapFaultDetails(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.SOAPFaultCodeElementName: soapFaultDetails.FaultCode = reader.ReadElementValue(); break; case XmlElementNames.SOAPFaultStringElementName: soapFaultDetails.FaultString = reader.ReadElementValue(); break; case XmlElementNames.SOAPFaultActorElementName: soapFaultDetails.FaultActor = reader.ReadElementValue(); break; case XmlElementNames.SOAPDetailElementName: soapFaultDetails.ParseDetailNode(reader); break; default: break; } } } while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPFaultElementName)); return soapFaultDetails; }
/// <summary> /// Loads AlternateMailbox instance from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>AlternateMailbox.</returns> internal static AlternateMailbox LoadFromXml(EwsXmlReader reader) { AlternateMailbox altMailbox = new AlternateMailbox(); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Type: altMailbox.Type = reader.ReadElementValue<string>(); break; case XmlElementNames.DisplayName: altMailbox.DisplayName = reader.ReadElementValue<string>(); break; case XmlElementNames.LegacyDN: altMailbox.LegacyDN = reader.ReadElementValue<string>(); break; case XmlElementNames.Server: altMailbox.Server = reader.ReadElementValue<string>(); break; case XmlElementNames.SmtpAddress: altMailbox.SmtpAddress = reader.ReadElementValue<string>(); break; case XmlElementNames.OwnerSmtpAddress: altMailbox.OwnerSmtpAddress = reader.ReadElementValue<string>(); break; default: break; } } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.AlternateMailbox)); return altMailbox; }
/// <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 from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.Type: this.ProtocolType = OutlookProtocol.ProtocolNameToType(reader.ReadElementValue()); break; case XmlElementNames.AuthPackage: this.authPackage = reader.ReadElementValue(); break; case XmlElementNames.Server: this.server = reader.ReadElementValue(); break; case XmlElementNames.ServerDN: this.serverDN = reader.ReadElementValue(); break; case XmlElementNames.ServerVersion: // just read it out reader.ReadElementValue(); break; case XmlElementNames.AD: this.activeDirectoryServer = reader.ReadElementValue(); break; case XmlElementNames.MdbDN: this.mailboxDN = reader.ReadElementValue(); break; case XmlElementNames.EWSUrl: this.exchangeWebServicesUrl = reader.ReadElementValue(); break; case XmlElementNames.EmwsUrl: this.exchangeManagementWebServicesUrl = reader.ReadElementValue(); break; case XmlElementNames.ASUrl: this.availabilityServiceUrl = reader.ReadElementValue(); break; case XmlElementNames.OOFUrl: // just read it out reader.ReadElementValue(); break; case XmlElementNames.UMUrl: this.unifiedMessagingUrl = reader.ReadElementValue(); break; case XmlElementNames.OABUrl: this.offlineAddressBookUrl = reader.ReadElementValue(); break; case XmlElementNames.PublicFolderServer: this.publicFolderServer = reader.ReadElementValue(); break; case XmlElementNames.Internal: OutlookProtocol.LoadWebClientUrlsFromXml(reader, this.internalOutlookWebAccessUrls, reader.LocalName); break; case XmlElementNames.External: OutlookProtocol.LoadWebClientUrlsFromXml(reader, this.externalOutlookWebAccessUrls, reader.LocalName); break; case XmlElementNames.Ssl: string sslStr = reader.ReadElementValue(); this.sslEnabled = sslStr.Equals("On", StringComparison.OrdinalIgnoreCase); break; case XmlElementNames.SharingUrl: this.sharingEnabled = reader.ReadElementValue().Length > 0; break; case XmlElementNames.EcpUrl: this.ecpUrl = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_um: this.ecpUrlUm = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_aggr: this.ecpUrlAggr = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_sms: this.ecpUrlSms = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_mt: this.ecpUrlMt = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_ret: this.ecpUrlRet = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_publish: this.ecpUrlPublish = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_photo: this.ecpUrlPhoto = reader.ReadElementValue(); break; case XmlElementNames.ExchangeRpcUrl: this.exchangeRpcUrl = reader.ReadElementValue(); break; case XmlElementNames.EwsPartnerUrl: this.exchangeWebServicesPartnerUrl = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_connect: this.ecpUrlConnect = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tm: this.ecpUrlTm = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tmCreating: this.ecpUrlTmCreating = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tmEditing: this.ecpUrlTmEditing = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_tmHiding: this.ecpUrlTmHiding = reader.ReadElementValue(); break; case XmlElementNames.SiteMailboxCreationURL: this.siteMailboxCreationURL = reader.ReadElementValue(); break; case XmlElementNames.EcpUrl_extinstall: this.ecpUrlExtInstall = reader.ReadElementValue(); break; case XmlElementNames.ServerExclusiveConnect: string serverExclusiveConnectStr = reader.ReadElementValue(); this.serverExclusiveConnect = serverExclusiveConnectStr.Equals("On", StringComparison.OrdinalIgnoreCase); break; case XmlElementNames.CertPrincipalName: this.certPrincipalName = reader.ReadElementValue(); break; case XmlElementNames.GroupingInformation: this.groupingInformation = reader.ReadElementValue(); break; default: reader.SkipCurrentElement(); break; } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Protocol)); }
/// <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> /// 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> /// 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> /// Load from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsXmlReader reader) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.AccountType: this.AccountType = reader.ReadElementValue(); break; case XmlElementNames.Action: string xmlResponseType = reader.ReadElementValue(); switch (xmlResponseType) { case OutlookAccount.Settings: this.ResponseType = AutodiscoverResponseType.Success; break; case OutlookAccount.RedirectUrl: this.ResponseType = AutodiscoverResponseType.RedirectUrl; break; case OutlookAccount.RedirectAddr: this.ResponseType = AutodiscoverResponseType.RedirectAddress; break; default: this.ResponseType = AutodiscoverResponseType.Error; break; } break; case XmlElementNames.Protocol: OutlookProtocol protocol = new OutlookProtocol(); protocol.LoadFromXml(reader); if (this.protocols.ContainsKey(protocol.ProtocolType)) { // There should be strictly one node per protocol type in the autodiscover response. throw new ServiceLocalException(Strings.InvalidAutodiscoverServiceResponse); } this.protocols.Add(protocol.ProtocolType, protocol); break; case XmlElementNames.RedirectAddr: case XmlElementNames.RedirectUrl: this.RedirectTarget = reader.ReadElementValue(); break; case XmlElementNames.AlternateMailboxes: AlternateMailbox alternateMailbox = AlternateMailbox.LoadFromXml(reader); this.alternateMailboxes.Entries.Add(alternateMailbox); break; default: reader.SkipCurrentElement(); break; } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Account)); }
/// <summary> /// Loads the domain setting errors. /// </summary> /// <param name="reader">The reader.</param> private void LoadDomainSettingErrorsFromXml(EwsXmlReader reader) { if (!reader.IsEmptyElement) { do { reader.Read(); if ((reader.NodeType == XmlNodeType.Element) && (reader.LocalName == XmlElementNames.DomainSettingError)) { DomainSettingError error = new DomainSettingError(); error.LoadFromXml(reader); domainSettingErrors.Add(error); } } while (!reader.IsEndElement(XmlNamespace.Autodiscover, XmlElementNames.DomainSettingErrors)); } }
/// <summary> /// Read SOAP headers. /// </summary> /// <param name="reader">EwsXmlReader</param> internal void ReadSoapHeaders(EwsXmlReader reader) { reader.ReadStartElement(XmlNamespace.Soap, XmlElementNames.SOAPHeaderElementName); do { reader.Read(); this.ReadSoapHeader(reader); } while (!reader.IsEndElement(XmlNamespace.Soap, XmlElementNames.SOAPHeaderElementName)); }
/// <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> /// Parses the XML through the specified reader and creates an Autodiscover error. /// </summary> /// <param name="reader">The reader.</param> /// <returns>An Autodiscover error.</returns> internal static AutodiscoverError Parse(EwsXmlReader reader) { AutodiscoverError error = new AutodiscoverError(); error.time = reader.ReadAttributeValue(XmlAttributeNames.Time); error.id = reader.ReadAttributeValue(XmlAttributeNames.Id); do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.ErrorCode: error.errorCode = reader.ReadElementValue<int>(); break; case XmlElementNames.Message: error.message = reader.ReadElementValue(); break; case XmlElementNames.DebugData: error.debugData = reader.ReadElementValue(); break; default: reader.SkipCurrentElement(); break; } } } while (!reader.IsEndElement(XmlNamespace.NotSpecified, XmlElementNames.Error)); return error; }