Autodiscover best practices
Last modified: October 13, 2012
Applies to: EWS Managed API | Exchange Server 2010
Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.
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.
The following example shows how to use the Autodiscover service to determine the best endpoint that is closest to the user's mailbox server.
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.
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.