【问题标题】:Exchagne Web Services - The Autodiscover service couldn't be locatedExchange Web 服务 - 找不到自动发现服务
【发布时间】:2020-11-09 11:59:39
【问题描述】:

我有一台 Exchange 2013 服务器 (Windows Server 2013)。具有所有角色的单一服务器域控制器、AD、Exchange 服务器等。现在我正在编写基本的 Exchange Web 服务示例代码。下面是我正在尝试的代码。如果在 Exchange 服务器本身上运行此代码,则会发送测试电子邮件。但是,如果我在同一域中的另一台 Windows 10 机器上运行相同的代码,它就不起作用。它在下面给出了例外。

在 Windows10 机器上,我已将 DNS IP 设置为指向 Windows Server 2013(Exchange 服务器),这样我就可以 ping 到 example.com。我在这里缺少什么,为什么此代码无法在同一域中的 Windows 10 机器上运行。

也不明白为什么,就是在找http://autodiscover.example.com。这不是我在任何地方定义的。

    static void Main(string[] args)
    {
        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.Credentials = new WebCredentials("User2001@example.com", "Pass@123");
        service.TraceEnabled = true;
        service.TraceFlags = TraceFlags.All;
        service.AutodiscoverUrl("User2001@example.com", RedirectionUrlValidationCallback);

        EmailMessage email = new EmailMessage(service);
        email.ToRecipients.Add("User2002@example.com");
        email.Subject = "HelloWorld";
        email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
        email.Send();
    }

    private static bool RedirectionUrlValidationCallback(string redirectionUrl)
    {
       return true;
    }

    Unhandled Exception: Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List`1 redirectionEmailAddresses, Int32& currentHop)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List`1 requestedSettings)
   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
   at EWSTest.Program.Main(String[] args) in c:\users\administrator\source\repos\EWSTest\EWSTest\Program.cs:line 18


    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:16Z">
    Starting SCP lookup for domainName='example.com', root path=''
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:20Z">
    Searching for SCP entries in LDAP://CN=Configuration,DC=example,DC=com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:21Z">
    Scanning for SCP pointers Domain=example.com
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:23Z">
    No SCP pointers found for 'Domain=example.com' in configPath='CN=Configuration,DC=example,DC=com'
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:24Z">
    Scanning for SCP urls for the current computer Site=Default-First-Site-Name
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:24Z">
    Adding (prio 1) 'https://NileshWin12Excg.example.com/Autodiscover/Autodiscover.xml' for the 'Site=Default-First-Site-Name' from 'LDAP://CN=NILESHWIN12EXCG,CN=Autodiscover,CN=Protocols,CN=NILESHWIN12EXCG,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=exampleOrg,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=example,DC=com' to the top of the list (exact match)
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:24Z">
    Trying to call Autodiscover for User2001@example.com on https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2020-11-08 05:52:25Z">
    POST /Autodiscover/Autodiscover.xml HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0913.015


    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="1" Time="2020-11-08 05:52:25Z" Version="15.00.0913.015">
      <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
        <Request>
          <EMailAddress>User2001@example.com</EMailAddress>
          <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
        </Request>
      </Autodiscover>
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
     failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
    Trying to call Autodiscover for User2001@example.com on https://example.com/autodiscover/autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2020-11-08 05:52:27Z">
    POST /autodiscover/autodiscover.xml HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0913.015


    </Trace>
    <Trace Tag="AutodiscoverRequest" Tid="1" Time="2020-11-08 05:52:27Z" Version="15.00.0913.015">
      <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
        <Request>
          <EMailAddress>User2001@example.com</EMailAddress>
          <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
        </Request>
      </Autodiscover>
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
     failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.)
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
    Trying to call Autodiscover for User2001@example.com on https://autodiscover.example.com/autodiscover/autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverRequestHttpHeaders" Tid="1" Time="2020-11-08 05:52:27Z">
    POST /autodiscover/autodiscover.xml HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    Accept: text/xml
    User-Agent: ExchangeServicesClient/15.00.0913.015


    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
     failed: WebException (The remote name could not be resolved: 'autodiscover.example.com')
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
    Trying to get Autodiscover redirection URL from http://autodiscover.example.com/autodiscover/autodiscover.xml.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
    Request error: The remote name could not be resolved: 'autodiscover.example.com'
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
    No Autodiscover redirection URL was returned.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:27Z">
    Trying to get Autodiscover host from DNS SRV record for example.com.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:28Z">
    DnsQuery returned error error 'DNS name does not exist' error code 0x0000232B.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:28Z">
    No appropriate SRV record was found.
    </Trace>
    <Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-11-08 05:52:28Z">
    No matching Autodiscover DNS SRV records were found.
    </Trace>

【问题讨论】:

    标签: c# exchange-server exchangewebservices


    【解决方案1】:

    您似乎遇到了安全连接问题;

    过程

    1. 客户端向 AD 发送 LDAP 查询
    2. AD 返回一个 SCP 点列表
    3. 客户端尝试连接到返回的点
    4. 如果返回有效响应,祝您天天开心。

    在您的情况下,服务器正在返回

    https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml - 结果:失败:WebException(底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。)

    https://example.com/autodiscover/autodiscover.xml - 结果:失败:WebException(底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。)

    http://autodiscover.example.com/autodiscover/autodiscover.xml - 结果:请求错误:无法解析远程名称:'autodiscover.example.com'

    因此,客户端似乎无法建立到https://nileshwin12excg.example.comhttps://example.com/ 的受信任连接,请尝试从您遇到问题的计算机访问这些 URL。您可能正在为您的 Web 服务使用自签名证书,而这些证书在客户端计算机上不受信任。

    编辑

    添加

    ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
    

    向您的启动告诉您应用程序始终接受服务器证书为有效。

    【讨论】:

    • 在服务器端,我在 EWS 和 AutoDiscoverer 的 IIS 设置下设置了忽略客户端证书。如果我尝试访问 example.comnileshwin12excg.example.com ,浏览器会打开 OWA 登录页面。 Windows 10 和 Windows Server 的防火墙均已禁用。
    • 这个“autodiscover.example.com”从何而来?我没有定义它。
    • 这是默认的,如果一切都失败了,客户端会尝试。
    • 不是服务器有问题,客户端正在尝试验证它的连接。给我一个 tic 看看你是否可以从客户端禁用 SSL
    • 我在上面的答案中添加了一个代码 sn-p 告诉服务点管理器忽略 SSL 验证,应该允许您的代码工作。
    猜你喜欢
    • 2019-10-16
    • 2013-11-23
    • 2012-09-28
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 2014-06-16
    相关资源
    最近更新 更多