1

我有 WCF 服务,我使用证书实现了消息安全性。但是当我尝试从我的客户端应用程序连接 WCF 服务时,我收到以下错误:

调用方未通过服务进行身份验证。

我的配置设置如下:

服务设置:

ServiceHost host = new ServiceHost(typeof(HostService));
NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.Message);
tcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
host.AddServiceEndpoint(typeof(IHostService), tcpBinding, "net.tcp://192.168.39.28:8000/HostService");
host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "server_cert");

客户端设置:

NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.Message);
tcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
DuplexChannelFactory<IHostService> serviceFactory = new DuplexChannelFactory<IHostService>(new InstanceContext(MainWindow), tcpBinding, "net.tcp://192.168.39.28:8000/HostService");
serviceFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "client_cert");
serviceFactory.CreateChannel();

我使用 makecert 命令创建了 server_cert 和 client_cert 证书。你能指导我错过什么吗?

4

1 回答 1

0

调试证书相关问题是一个很大的痛苦,我强烈推荐使用wireshark。在您的情况下,您的客户端可能甚至没有发送证书。如果客户端证书由另一个证书签名,请确保将它(它们)放入客户端和服务器上的受信任根目录中。

于 2012-05-31T19:44:18.923 回答