C# 尝试使用 EWS MANAGED API 访问 Exchange 2010 帐户时,“无法找到自动发现服务”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15065363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:56:31  来源:igfitidea点击:

'Autodiscover service couldn't be located' when trying to access Exchange 2010 account with EWS MANAGED API

c#exchange-serverexchangewebservicesews-managed-api

提问by user1891567

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

我正在为指定的电子邮件地址使用自动发现服务 Url。

ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2010);
Service.Credentials = new WebCredentials("[email protected]", "Password");
Service.AutodiscoverUrl("[email protected]");
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?

我该怎么做才能避免这个错误?

回答by Alex

You got Service.Credentialswrong, use it like this:

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

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

Using domain credentials, not the email address.

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

Also doublecheck the following:

还要仔细检查以下内容:

  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)
  1. 您在new ExchangeService()匹配服务器中指定的版本
  2. 传递给的参数Service.AutodiscoverUrl();正确(需要获取数据的邮箱地址)

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("[email protected]");
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

回答by cmchenry

I'd recommend that you verify that autodiscover is actually setup in DNS. The following article explains how to set it up in more detail and it also gives you information on how to test it with the Microsoft Remote Connectivity Analyzer.http://www.petri.co.il/autodiscover-configuration-exchange-2010.htm

我建议您验证自动发现实际上是在 DNS 中设置的。以下文章更详细地解释了如何设置它,还提供了有关如何使用 Microsoft 远程连接分析器对其进行测试的信息。http://www.petri.co.il/autodiscover-configuration-exchange-2010.htm

回答by cenday

try to use this:

尝试使用这个:

Service.Credentials = new WebCredentials("john", "12345678", "MYDOMAIN");

NOT this one

不是这个

Service.Credentials = new WebCredentials("[email protected]", "12345678", "MYDOMAIN");

notice the username is 'john'NOT '[email protected]',It blocked me for quite a few hours for using the second one....

请注意用户名'john'不是'[email protected]',它阻止了我使用第二个用户名好几个小时....

回答by nitesh.kodle123

I will recommend to you to enable Traces,to achieve this follow :

我会建议您启用跟踪,以实现以下目标:

     Service.TraceEnabled = true;

I was facing the same issue then when I enabled traces these traces will guide you what exactly is happening.In my case SSL certificate issue is there to solve it i followed following post

我遇到了同样的问题,然后当我启用跟踪时,这些跟踪将指导您到底发生了什么。在我的情况下,SSL 证书问题可以解决它,我遵循以下帖子

There can be many issue such as:

可能有很多问题,例如:

  • User can be blocked.
  • The DNS can't find autodiscover.domain.com.
  • 用户可以被阻止。
  • DNS 找不到autodiscover.domain.com.

回答by Vasile Tomoiaga

I experienced the same problem with Exchange 2013. In my case the cause was a Default Proxy declaration in my config file, which probably prevented the Autodiscover service to work correctly.

我在 Exchange 2013 中遇到了同样的问题。就我而言,原因是我的配置文件中的默认代理声明,这可能会阻止自动发现服务正常工作。

<system.net>
    <defaultProxy enabled="true">
      <proxy proxyaddress="http://localhost:8888" bypassonlocal="False"/>
    </defaultProxy>
</system.net>

After commenting the <defaultProxy>tag, autodiscover was able to find the service Url.

注释<defaultProxy>标签后,自动发现能够找到服务 URL。

回答by user3531993

Let me point out that if you are trying to access Office 365 then the web credentials really are of the form WebCredentials(strUsername, strPassword); with strUsername being the email address of the account you are trying to access.

让我指出,如果您尝试访问 Office 365,那么 Web 凭据实际上是 WebCredentials(strUsername, strPassword); 形式的。strUsername 是您尝试访问的帐户的电子邮件地址。

I was getting this error and it turned out someone had changed the password on the account without informing me! What an odd error to get when it's just a bad password!

我收到此错误,结果有人在没有通知我的情况下更改了帐户的密码!当它只是一个错误的密码时,会出现多么奇怪的错误!

回答by Gigabyte

For the record of completeness:

为了完整性的记录:

We encountered a service suddenly stopping with this particular error. As the service had been running unattended for months, using EWS to monitor a mailbox, it turned out that the password was expired. This caused the AutoDiscovery to fail with the very same exception:

我们遇到了一个服务突然因这个特定错误而停止。由于该服务已无人值守运行数月,使用 EWS 监控邮箱,结果发现密码已过期。这导致自动发现失败,并出现相同的异常:

The Autodiscover service couldn't be located

找不到自动发现服务

Updating the Exchange user's password in the AD and checking its Password Never Expiresproperty solved the problem for us.

更新 AD 中 Exchange 用户的密码并检查其Password Never Expires属性为我们解决了问题。

回答by Carlos ABS

Check if the password for this email has expired.

检查此电子邮件的密码是否已过期。

If the password has expired you receive this error from AutoDiscover.

如果密码已过期,您会从 AutoDiscover 收到此错误。

回答by Chris Lee

I have hit this and a trace shows that after using the proxy to access 365 it starts a DNS lookup for an SVC record. This lookup goes to internal DNS and not the proxy, our internal DNS does not resolve external DNS entries, that is why we have proxy servers. Not yet found out why it is doing a DNS lookup rather than using the proxy servers, but that is what is causing our version of this problem

我遇到了这个问题,跟踪显示在使用代理访问 365 后,它会开始对 SVC 记录进行 DNS 查找。此查找转到内部 DNS 而不是代理,我们的内部 DNS 不解析外部 DNS 条目,这就是我们拥有代理服务器的原因。尚未发现为什么它进行 DNS 查找而不是使用代理服务器,但这就是导致我们出现此问题的版本的原因

回答by Dzmitry Lahoda

I have used direct:

我直接用过:

Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx")

and it worked for me. You may try use Fiddlerand eM Clientto see how they use EWS Managed APIto get things done and replicate calls.

它对我有用。您可以尝试使用FiddlereM Client来查看它们如何用于EWS Managed API完成任务和复制调用。