Exchange Web 服务 - 无法找到自动发现服务
Exchagne Web Services - The Autodiscover service couldn't be located
我有一个 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>
您似乎遇到了安全连接问题;
进程
- 客户端向 AD 发送 LDAP 查询
- AD returns SCP点列表
- 客户端尝试连接到返回的点
- 如果收到有效回复,祝你好运。
在您的情况下,服务器正在返回
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.com or https://example.com/ 建立可信连接,请尝试从出现问题的计算机访问这些 URL。可能是您正在为您的 Web 服务使用 self-signed 证书,而这些证书在客户端计算机上不受信任。
编辑
添加
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
到您的启动程序,告诉您应用程序始终接受服务器证书为有效。
我有一个 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>
您似乎遇到了安全连接问题;
进程
- 客户端向 AD 发送 LDAP 查询
- AD returns SCP点列表
- 客户端尝试连接到返回的点
- 如果收到有效回复,祝你好运。
在您的情况下,服务器正在返回
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.com or https://example.com/ 建立可信连接,请尝试从出现问题的计算机访问这些 URL。可能是您正在为您的 Web 服务使用 self-signed 证书,而这些证书在客户端计算机上不受信任。
编辑
添加
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
到您的启动程序,告诉您应用程序始终接受服务器证书为有效。