【发布时间】:2009-04-08 19:00:27
【问题描述】:
我正在尝试使用 BasicHttpBinding 在传输级别使用 SSL 证书相互验证 WCF 服务器和客户端。以下是服务器的创建方式:
var soapBinding = new BasicHttpBinding() { Namespace = "http://test.com" };
soapBinding.Security.Mode = BasicHttpSecurityMode.Transport;
soapBinding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Certificate;
var sh = new ServiceHost(typeof(Service1), uri);
sh.AddServiceEndpoint(typeof(IService1), soapBinding, "");
sh.Credentials.ServiceCertificate.SetCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName, "localhost");
sh.Open();
这是客户:
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
var service = new ServiceReference2.Service1Client(binding,
new EndpointAddress("https://localhost:801/Service1"));
service.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName, "localhost");
service.ClientCredentials.ServiceCertificate.Authentication.
CertificateValidationMode =
System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;
service.HelloWorld();
localhost 的证书位于个人、受信任的根和受信任的第 3 方容器中。 Internet Explorer 可以连接到主机并查看 WSDL。此外,SSL 调用适用于 ClientCredentialType = HttpClientCredentialType.None
HelloWorld() 失败:
System.ServiceModel.Security.MessageSecurityException occurred<br/>
Message="The HTTP request was forbidden with client authentication
scheme 'Anonymous'."
这是一个重新抛出的异常:“远程服务器返回错误:(403) Forbidden。”
如何弄清楚 wtf 是怎么回事?
【问题讨论】:
标签: wcf web-services