This topic has not yet been rated - Rate this topic

Autodiscover best practices

EWS Managed API

Published: July 16, 2012

Applies to:  Exchange 2013 | Exchange Online | Exchange Server 2010 | Exchange Web Services (EWS) Managed API 

The Autodiscover service enables you to retrieve configuration information for any user in your domain. This topic provides some best practices for working with the Autodiscover service.

If the URL of the Exchange Web Services (EWS) endpoint is already known, you do not need to use the Autodiscover service to make the connection. However, you can set the URL manually or use the best endpoint for a given user. Because the location of the best endpoint for a given user can change, for example when a new Client Access server is deployed, or can vary depending on the user, we recommend that you use the Autodiscover service.

The following example shows how to manually set the URL of the EWS endpoint.

service.Url = new Uri("https://mail.Contoso.com/EWS/Exchange.asmx");

The following example shows how to use the Autodiscover service to determine the best endpoint that is closest to the user's mailbox server.

service.AutodiscoverUrl("User1@Contoso.com");

If you try to perform an autodiscovery on a nonexistent e-mail address, your attempt will result in an error. To prevent an invalid address from causing an application failure, we recommend that you include the AutodiscoverUrl call in a Try/Catch block. The following example shows how to use a Try/Catch block to handle the exception and to display the error message. When the e-mail address does not exist in the domain, an exception is thrown and the following message is displayed:

The e-mail address cannot be found.

// Set the URL.
try
{
    service.AutodiscoverUrl("User1_with_a_non_existent_name@Contoso.com");
}
catch (AutodiscoverRemoteException ex)
{
    Console.WriteLine("Exception thrown: " + ex.Error.Message);
}

The Autodiscover service enables client applications to retrieve many configuration settings. However, this consumes bandwidth and possibly exposes the configuration settings. We recommend that you use the GetUserSettings(String, []) method to retrieve only the specific configuration settings that are required. In the following example, only four settings are requested: UserDisplayName, InternalMailboxServer, PublicFolderServer, and ExternalMailboxServer.

GetUserSettingsResponse userresponse = autodiscoverService.GetUserSettings(
    "User1@Contoso.com",
    UserSettingName.UserDisplayName,
    UserSettingName.InternalMailboxServer,
    UserSettingName.PublicFolderServer,
    UserSettingName.ExternalMailboxServer);

Date

Description

July 16, 2012

Initial publication

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.