我正在尝试使用msdn示例理解基于证书的身份验证
https://msdn.microsoft.com/en-us/library/ms731074(v=vs.90).aspx
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
// Create the URI for the endpoint.
Uri httpUri = new Uri("https://localhost/Calculator");
// Create the service and add an endpoint.
ServiceHost myServiceHost = new ServiceHost(typeof(ServiceModel.Calculator), httpUri);
myServiceHost.AddServiceEndpoint(typeof(ServiceModel.ICalculator), binding, "");
// Open the service.
myServiceHost.Open();
Console.WriteLine("Listening...");
Console.ReadLine();
// Close the service.
myServiceHost.Close();
ChannelFactory<ICalculator> factory = null;
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
EndpointAddress address = new EndpointAddress("https://localhost/Calculator");
factory = new ChannelFactory<ICalculator>(binding, address);
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
factory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "sroger");
ICalculator channel = factory.CreateChannel();
int y = channel.add(9, 8);
我遇到以下例外情况:
“System”类型的未处理异常。服务模型。mscorlib中出现“CommunicationException”。dll
https://localhost/Calculator
. 这可能是因为服务器证书没有正确配置HTTP。HTTPS情况下的SYS。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。
我在同一台机器上运行客户端和服务器。“sroger”是我当前用户\个人\证书中的证书,对应于我的机器名。。
不知道该怎么办。。有什么想法吗?
在服务器代码中,服务器使用什么证书?
古鲁马尔。