AutodiscoverUrlWithCallback method

Future<void> AutodiscoverUrlWithCallback(
  1. String emailAddress,
  2. AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback
)
Initializes the Url property to the Exchange Web Services URL for the specified e-mail address by calling the Autodiscover service. The email address to use. The callback used to validate redirection URL.

Implementation

Future<void> AutodiscoverUrlWithCallback(
    String emailAddress,
    AutodiscoverRedirectionUrlValidationCallback
        validateRedirectionUrlCallback) async {
  Uri exchangeServiceUrl;

  if (this.RequestedServerVersion.index >
      ExchangeVersion.Exchange2007_SP1.index) {
    try {
      exchangeServiceUrl = await this
          .GetAutodiscoverUrlWithExchangeVersionAndCallback(emailAddress,
              this.RequestedServerVersion, validateRedirectionUrlCallback);

      this.Url = this.AdjustServiceUriFromCredentials(exchangeServiceUrl);
      return;
    } on AutodiscoverLocalException catch (ex) {
      this.TraceMessage(enumerations.TraceFlags.AutodiscoverResponse,
          "Autodiscover service call failed with error '${ex.message}'. Will try legacy service");
    } on ServiceRemoteException catch (ex) {
      // Special case: if the caller's account is locked we want to return this exception, not continue.
      if (ex is AccountIsLockedException) {
        throw ex;
      }

      this.TraceMessage(enumerations.TraceFlags.AutodiscoverResponse,
          "Autodiscover service call failed with error '${ex.message}'. Will try legacy service");
    }
  }

  // Try legacy Autodiscover provider
  exchangeServiceUrl = await this
      .GetAutodiscoverUrlWithExchangeVersionAndCallback(emailAddress,
          ExchangeVersion.Exchange2007_SP1, validateRedirectionUrlCallback);

  this.Url = this.AdjustServiceUriFromCredentials(exchangeServiceUrl);
}