简体   繁体   English

Exchagne Web 服务 - 无法找到自动发现服务

[英]Exchagne Web Services - The Autodiscover service couldn't be located

I have a Exchange 2013 server (Windows Server 2013).我有一台 Exchange 2013 服务器(Windows Server 2013)。 Single server with all roles Domain controller, AD, Exchange server etc. Now I am writing basic Exchange web services sample code.具有所有角色的单个服务器域控制器、AD、Exchange 服务器等。现在我正在编写基本的 Exchange Web 服务示例代码。 Below is the code I am trying.下面是我正在尝试的代码。 If run this code on Exchange server itself, test email gets sent.如果在 Exchange 服务器本身上运行此代码,则会发送测试电子邮件。 But if I run same code on another Windows 10 machine in same domain, it does not works.但是,如果我在同一域中的另一台 Windows 10 机器上运行相同的代码,则它不起作用。 It gives exception below.它在下面给出了例外。

On Windows10 machine I have set DNS IP to point Windows Server 2013(Exchange server), with that I can ping to example.com.在 Windows10 机器上,我已将 DNS IP 设置为指向 Windows Server 2013(Exchange 服务器),这样我就可以 ping 到 example.com。 What I am missing here, why this code is not working on Windows 10 machine in same domain.我在这里缺少什么,为什么此代码在同一域中的 Windows 10 机器上不起作用。

Also did not understand why, it is looking for http://autodiscover.example.com .也不明白为什么,它正在寻找http://autodiscover.example.com This is not I have defined anywhere.这不是我在任何地方定义的。

    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>

Looks like you having secure connection issues;看起来您有安全连接问题;

Process过程

  1. Client sends LDAP query to the AD客户端向 AD 发送 LDAP 查询
  2. AD returns a list of SCP points AD 返回 SCP 点列表
  3. Client attempts to connect to the returned points客户端尝试连接到返回的点
  4. If a valid response comes back, happy days.如果有效的回应回来了,快乐的日子。

In your case the server is returning在您的情况下,服务器正在返回

https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml - Result : failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.) https://nileshwin12excg.example.com/Autodiscover/Autodiscover.xml - 结果:失败:WebException(底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。)

https://example.com/autodiscover/autodiscover.xml - Result : failed: WebException (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.) https://example.com/autodiscover/autodiscover.xml - 结果:失败:WebException(底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。)

http://autodiscover.example.com/autodiscover/autodiscover.xml - Result : Request error: The remote name could not be resolved: 'autodiscover.example.com' http://autodiscover.example.com/autodiscover/autodiscover.xml - 结果:请求错误:无法解析远程名称:'autodiscover.example.com'

So it would seem that the client can not establish a trusted connection to https://nileshwin12excg.example.com or https://example.com/ , try to get to these URLs from the machine where you are having trouble.因此,客户端似乎无法建立到https://nileshwin12excg.example.comhttps://example.com/的可信连接,尝试从遇到问题的机器访问这些 URL。 It may be you are using self-signed certs for your web services that are not trusted on the client machine.可能是您正在为客户端计算机上不受信任的 Web 服务使用自签名证书。

EDIT编辑

Add添加

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

To your startup to tell you application to always accept the server certificate as valid.到您的启动告诉您应用程序始终接受服务器证书为有效。

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

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