EWS 失败,无法创建 SSL/TLS 安全通道

本文关键字:TLS 安全 通道 SSL 创建 失败 EWS | 更新日期: 2023-09-27 17:56:13

我正在尝试使用 EWS 获取忙/闲我安装了最新的nuget包Microsoft.Exchange.WebServices

我还设置了我所知道的所有内容以忽略证书错误:

    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 |  SecurityProtocolType.Ssl3;

我用来获取约会的代码:

 //Set up the service with correct credentials.
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
{
    Credentials = new WebCredentials(Account, Password, Domain), 
    TraceEnabled = true, 
    EnableScpLookup = false
};
service.Url = new Uri(ServiceUrl);
// Create a list of attendees.
var attendees = Contacts.Select(contact => new AttendeeInfo { SmtpAddress = contact.Email, AttendeeType = MeetingAttendeeType.Required }).ToList();
// Specify availability options.
var myOptions = new AvailabilityOptions
                {
                    MeetingDuration = 30, 
                    RequestedFreeBusyView = FreeBusyViewType.DetailedMerged,
                    DetailedSuggestionsWindow = new TimeWindow(DateTime.Now, DateTime.Now.AddDays(Days))
                };
// Return a set of free/busy times.
var freeBusyResults = service.GetUserAvailability(attendees, new TimeWindow(DateTime.Now, DateTime.Now.AddDays(Days)),AvailabilityData.FreeBusyAndSuggestions, myOptions);

此代码适用于我拥有的 6 台交换服务器中的 5 台,但其中一台给出"请求失败。请求已中止:无法创建 SSL/TLS 安全通道"错误消息。

如果我设置小提琴手作为呼叫的代理,并告诉小提琴手解密,一切正常。

我只想忽略所有 SSL 错误并获取数据,我该怎么做?

EWS 失败,无法创建 SSL/TLS 安全通道

托管 API 只是使用 HTTPWebRequest 作为执行请求/响应的基础类。如果它适用于小提琴手,您的问题很可能与环境/客户有关。我建议您启用跟踪 https://blogs.msdn.microsoft.com/dgorti/2005/09/18/using-system-net-tracing/然后您应该能够看到当它失败时在较低级别会发生什么。