我使用這個醜陋的黑客只在單元測試:(
的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;
}
不是說明性的,但你可以使用Fiddler解決證書驗證問題和傻瓜svcutil :) – 2012-08-08 13:31:11