c# calling web service error: "The client certificate is Not provided. Specify a client certificate in client credentials"

c# calling web service error: "The client certificate is Not provided. Specify a client certificate in client credentials"

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

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);

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

"The client certificate is Not provided. Specify a client certificate in client credentials"

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

谢谢,

您可以在 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();
// ...