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 (RequestedServerVersion.index > ExchangeVersion.Exchange2007_SP1.index) {
    try {
      exchangeServiceUrl =
          await GetAutodiscoverUrlWithExchangeVersionAndCallback(
            emailAddress,
            RequestedServerVersion,
            validateRedirectionUrlCallback,
          );

      Url = AdjustServiceUriFromCredentials(exchangeServiceUrl);
      return;
    } on AutodiscoverLocalException catch (ex) {
      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) {
        rethrow;
      }

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

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

  Url = AdjustServiceUriFromCredentials(exchangeServiceUrl);
}