我正试图通过我的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和证书的了解有限。有谁知道解决这个问题?
谢谢,
答案 0 :(得分: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();
// ...