简体   繁体   English

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

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

I am using Auto discover service Url for a specified e-mail address.我正在为指定的电子邮件地址使用自动发现服务 Url。

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?我必须做些什么来避免这个错误?

You got Service.Credentials wrong, 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您在new ExchangeService()中指定的版本与服务器的
  2. the parameter passed to Service.AutodiscoverUrl();传递给Service.AutodiscoverUrl();的参数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

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);让我指出,如果您尝试访问 Office 365,那么 Web 凭据实际上是 WebCredentials(strUsername, strPassword); 形式的。 with strUsername being the email address of the account you are trying to access. 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!当它只是一个错误的密码时,会出现多么奇怪的错误!

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

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.由于该服务已无人值守运行数月,使用 EWS 监控邮箱,结果发现密码已过期。 This caused the AutoDiscovery to fail with the very same exception:这导致自动发现失败,并出现相同的异常:

The Autodiscover service couldn't be located找不到自动发现服务

Updating the Exchange user's password in the AD and checking its Password Never Expires property solved the problem for us.更新 AD 中 Exchange 用户的密码并检查其Password Never Expires属性为我们解决了问题。

try to use this:尝试使用这个:

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

NOT this one不是这个

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

notice the username is 'john' NOT 'john@mail.com' ,It blocked me for quite a few hours for using the second one....请注意,用户名是'john'不是'john@mail.com' ,因为使用第二个用户名,它阻止了我好几个小时......

Check if the password for this email has expired.检查此电子邮件的密码是否已过期。

If the password has expired you receive this error from AutoDiscover.如果密码已过期,您会从 AutoDiscover 收到此错误。

I have used direct:我直接用过:

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

and it worked for me.它对我有用。 You may try use Fiddler and eM Client to see how they use EWS Managed API to get things done and replicate calls.您可以尝试使用FiddlereM Client来查看它们如何使用EWS Managed API来完成任务和复制调用。

I'd recommend that you verify that autodiscover is actually setup in DNS.我建议您验证自动发现实际上是在 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.以下文章更详细地解释了如何设置它,还提供了有关如何使用 Microsoft 远程连接分析器对其进行测试的信息。 http://www.petri.co.il/autodiscover-configuration-exchange-2010.htm http://www.petri.co.il/autodiscover-configuration-exchange-2010.htm

Faced this issue for specific user.面对特定用户的这个问题。 After checking I found that user has enabled two factor authentication and using his primary password for connection.检查后我发现用户已启用两因素身份验证并使用他的主密码进行连接。 Solved by generating app specific password and connecting with it.通过生成应用程序特定密码并与之连接来解决。 Disabling two factor also worked, but it will take some time to reflect.禁用两个因素也有效,但需要一些时间来反映。 Not sure why exchange gave "The Autodiscover service couldn't be located."不知道为什么交换会给出“无法找到自动发现服务”。 instead of "Unauthorised".而不是“未经授权”。

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。

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

This solved my problem: 这解决了我的问题:

https://support.neuxpower.com/hc/en-us/articles/202482832-Determining-the-Exchange-Web-Services-EWS-URL https://support.neuxpower.com/hc/zh-CN/articles/202482832-确定-Exchange-Web-Services-EWS-URL

A company will most probably disable the auto detect feature of exchange web service for security reason. 公司出于安全原因很可能会禁用Exchange Web服务的自动检测功能。 The method 2 in above article guides me to find the exchange service url used in my company. 上一篇文章中的方法2指导我找到我公司中使用的交换服务URL。

发生此错误...原来我的密码已过期,需要更改。

The 'Autodiscover service couldn't be located' error message has nothing to do with Autodiscover not working properly. “找不到自动发现服务”错误消息与自动发现无法正常工作无关。 Instead, it's related to an authentication issue.相反,它与身份验证问题有关。

Microsoft's documentation examples are still using Basic Authentication. Microsoft 的文档示例仍在使用基本身份验证。 However, as you can see in this blog post , Basic Auth should be turned off by end of 2022. So, instead of following exactly Microsoft's code examples, you will have to modify the auth section to use OAuth 2.0.但是,正如您在这篇博文中看到的那样,基本身份验证应在 2022 年底关闭。因此,您必须修改身份验证部分以使用 OAuth 2.0,而不是完全遵循 Microsoft 的代码示例。 This article helped me get things to work. 这篇文章帮助我完成了工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM