Я использую этот уродливый хак для использования только в UnitTests: (
app.config:
<system.net>
<webRequestModules xdt:Transform="Insert">
<clear/>
<add prefix = "http" type = "HttpRequestCreatorWithServerCertificateValidationCallback, TestHelpers"/>
<add prefix = "https" type = "HttpRequestCreatorWithServerCertificateValidationCallback, TestHelpers"/>
</webRequestModules>
</system.net>
HttpRequestCreatorWithServerCertificateValidationCallback.cs
public class HttpRequestCreatorWithServerCertificateValidationCallback : IWebRequestCreate
{
static HttpRequestCreatorWithServerCertificateValidationCallback()
{
var type = typeof(HttpWebRequest).Assembly.GetType("System.Net.HttpRequestCreator");
var ctor = type.GetConstructors()[0];
Creator = (IWebRequestCreate)ctor.Invoke(null);
ServicePointManager.ServerCertificateValidationCallback += delegate
{
return true;
};
}
#region IWebRequestCreate Members
public WebRequest Create(Uri uri)
{
return Creator.Create(uri);
}
#endregion
private static readonly IWebRequestCreate Creator;
}