【问题标题】:c# calling web service error: "The client certificate is Not provided. Specify a client certificate in client credentials"c#调用Web服务错误:“未提供客户端证书。在客户端凭据中指定客户端证书”
【发布时间】:2015-04-18 22:30:50
【问题描述】:

我正在尝试从我的 mvc3 应用程序通过 https 调用我服务器上的 Web 服务。我在这个地址有网络服务:

https:localhost/web_services/web_services.asmx

在我的代码中,我尝试像这样连接:

 var binding = new BasicHttpsBinding();
 binding.maxbuffersize = 10000;
 binding.maxbufferPoolsize = 10000; 
 binding.maxreceivedmessageSize= 10000;
 binding.Security.Mode = System.ServiceModel.BasicHttpsSecurityMode.Transport;
 binding.Security.Transport.ClientCredentialsType = HttpClientCredentialType.Certificate


 var endpointAddress = new EndpointAddress("https:/localhost/web_services/web_services.asmx");
 new ChannelFactory<ws_name_webreqSoap>(basicHttpsBinding, endpointAddress).CreateChannel();
 var webServices = new ws_name_webreqSoapClient(basicHttpsBinding, endpointAddress);

但是,当它在服务器上运行时,我收到以下消息:

“未提供客户端证书。在客户端凭据中指定客户端证书”

我对 HTTPS 和证书的了解有限。有谁知道这个问题的解决方案吗?

谢谢,

【问题讨论】:

    标签: c# web-services https certificate


    【解决方案1】:

    您可以在 ChannelFactory 上指定客户端证书:

    var channelFactory = new ChannelFactory<ws_name_webreqSoap>(basicHttpsBinding, endpointAddress);
    channelFactory.Credentials.ClientCertificate.SetCertificate("CN=client.com", StoreLocation.CurrentUser, StoreName.My);
    var channel = channelFactory.CreateChannel();
    // ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 2013-06-06
      相关资源
      最近更新 更多