尝试使用EWS MANAGED API访问Exchange 2010帐户时“找不到自动发现服务"

问题描述:

我正在使用自动发现服务URL来指定电子邮件地址.

I am using Auto discover service Url for a specified e-mail address.

ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2010);
Service.Credentials = new WebCredentials("username@domainname.com", "Password");
Service.AutodiscoverUrl("username@domainname.com");
Folder inbox = Folder.Bind(Service, WellKnownFolderName.Inbox);
Console.WriteLine("The folder name is" + inbox.DisplayName.ToString());

如果我这样做,我会出错:

If I do like this I'm gettin an error:

找不到自动发现服务

The Autodiscover service couldn't be located

为避免此错误我该怎么做?

What I have to do to avoid this error?

您弄错了Service.Credentials,请像这样使用它:

You got Service.Credentials wrong, use it like this:

Service.Credentials = new WebCredentials(username, password, domainname);

使用域凭据,而不是电子邮件地址.

Using domain credentials, not the email address.

还要仔细检查以下内容:

Also doublecheck the following:

  1. 您在new ExchangeService()中指定的版本与服务器的
  2. 匹配
  3. 传递给Service.AutodiscoverUrl();的参数正确(需要获取数据的电子邮件地址)
  1. The version you specify in new ExchangeService() matches server's
  2. the parameter passed to Service.AutodiscoverUrl(); is correct (email address which data needs to be fetched)

以下对我有用(在新的控制台应用程序中):

The following works for me (in a new Console Application):

// Tweaked to match server version
ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); 

// Dummy but realistic credentials provided below
Service.Credentials = new WebCredentials("john", "12345678", "MYDOMAIN");
Service.AutodiscoverUrl("john.smith@mydomain.it");
Folder inbox = Folder.Bind(Service, WellKnownFolderName.Inbox);
Console.WriteLine("The folder name is " + inbox.DisplayName.ToString());

//Console output follows (IT localized environment, 'Posta in arrivo' = 'Inbox')
> The folder name is Posta in arrivo