无法以编程方式连接到 Exchange 2019

Cannot connect to Exchange 2019 programmatically

我的代码可以很好地连接到 Exchange 2017,但升级到 2019 后它就停止工作了。

例外情况是:

<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-04-25 00:48:18Z">
Trying to call Autodiscover for username@mydomain.com on https://subdomain.mydomain.com/autodiscover/autodiscover.xml.
</Trace>
<Trace Tag="AutodiscoverConfiguration" Tid="1" Time="2020-04-25 00:48:19Z">
 failed: WebException (The underlying connection was closed: An unexpected error occurred on a send.)
</Trace>

如您所见,我启用了跟踪功能。 证书很好,我可以从浏览器连接到 https://subdomain.mydomain.com/autodiscover/autodiscover.xml

有什么问题吗?

代码如下:

Dim service As New ExchangeService(ExchangeVersion.Exchange2013_SP1)

service.TraceListener = New TraceListener()
service.TraceEnabled = True
service.Credentials = New WebCredentials(Username, Password)
service.AutodiscoverUrl(EmailAddress, AddressOf RedirectionCallback)

最可能的原因是 TLS 1.2,因为 Exchange 2019 将只接受 TLS 1.2 连接,我建议您从 github [=11= 编译最新版本的 EWS Managed API ] 并且您还可以显式设置 TLS 版本

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;