ExchangeService.AutodiscoverUrl method (String)

Initializes the Url property to the Exchange Web Services (EWS) endpoint for a specified email address by calling the Autodiscover service.

Namespace:  Microsoft.Exchange.WebServices.Data
Assembly:  Microsoft.Exchange.WebServices (in Microsoft.Exchange.WebServices.dll)

public void AutodiscoverUrl(
	string emailAddress


Type: System.String

The email address to be used.


A local failure, such as a blocked redirection or a number of redirections greater than the maximum, caused Autodiscover to stop.


The Autodiscover server returned an error.


An empty value was passed in the emailAddress parameter.

If an Autodiscover server returns a redirect HTTP status code, this method will generate an AutodiscoverLocalException with the Message property set to a string such as "Autodiscover blocked a potentially insecure redirection to To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload." This exception is generated for all redirect responses, regardless of the validity of the URL returned in the redirect response.

To enable redirection, use the AutodiscoverUrl(String, AutodiscoverRedirectionUrlValidationCallback) overload instead.

The following example shows how to get the user's EWS URL by using the AutodiscoverUrl(String) method.

using System.Net;
using System.Security;
using Microsoft.Exchange.WebServices.Data;

static void GetUsersEwsUrl(string userEmailAddress, SecureString userPassword)
    ExchangeService service = new ExchangeService();

    // Set specific credentials.
    service.Credentials = new NetworkCredential(userEmailAddress, userPassword);

    // Look up the user's EWS endpoint by using Autodiscover.

    Console.WriteLine("EWS Endpoint: {0}", service.Url);