How to stop certificate errors temporarily with WCF services

后端 未结 5 772
独厮守ぢ
独厮守ぢ 2020-12-29 07:59

I am testing an early release of a WCF web service I have created. On the client side when I use VS to \'add service reference\' that all works.

But when I try to us

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 08:39

    You could also override with this oneliner.

    ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
    

    Simply paste it into the generated WCF client constructor in Reference.cs

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class WebQuoteServiceClient : System.ServiceModel.ClientBase, Corp.Legal.Webservices.ServiceReference1.IWebQuoteService {
    
        public WebQuoteServiceClient()
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
        }
    

提交回复
热议问题