Export (0) Print
Expand All

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)

'Declaration
Public Sub AutodiscoverUrl ( _
	emailAddress As String _
)
'Usage
Dim instance As ExchangeService
Dim emailAddress As String

instance.AutodiscoverUrl(emailAddress)

Parameters

emailAddress
Type: System.String

The email address to be used.

ExceptionCondition
AutodiscoverLocalException

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

AutodiscoverRemoteException

The Autodiscover server returned an error.

ServiceValidationException

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 https://autodiscover.contoso.com/autodiscover/autodiscover.xml. 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.
    service.AutodiscoverUrl(userEmailAddress);

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