synic synic - 25 days ago 6
C# Question

EWS and TLS 1.2 - having issues connecting automatically

One of our clients has upgraded to Tls 1.2.

However, the

ExchangeService
client has problems connecting to it, unless I add the following code:

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


This likely won't work for all of our clients. Is there a way to make it detect which one to use automatically?

Answer

You can specify multiple supported protocols by doing something like this:

System.Net.ServicePointManager.SecurityProtocol =
    SecurityProtocolType.Ssl3 |
    SecurityProtocolType.Tls |
    SecurityProtocolType.Tls11 |
    SecurityProtocolType.Tls12;

Using this sample of code, you allow all security protocols (supported by .NET).