使用带有自签名证书的传输安全性的 BasicHttpBinding

Yua*_*uan 5 ssl wcf certificate

我有 WCF 服务,在一个 ServiceHost 内的不同端点使用 BasicHttpBinding 和 NetTcpBinding。NetTcp 使用自签名证书,该证书是从文件加载的,一切都很好,直到我尝试实际使用 BasicHttpBinding,所以我这样做:

在服务器上:

var ServiceHost host = new ServiceHost(blah blah);
host.Credentials.ServiceCertificate.Certificate = GetCertificate(); //load a certificate from file
host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
var httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
Run Code Online (Sandbox Code Playgroud)

在客户端:

ChannelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
var cer = GetCertificate();
ChannelFactory.Credentials.ClientCertificate.Certificate = cer;

var httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
//accept any cert
System.Net.ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);
Run Code Online (Sandbox Code Playgroud)

但是当连接时,我收到此错误

异常 - 向https://localhost/MyService发出 HTTP 请求时发生错误 。这可能是由于在 HTTPS 情况下未使用 HTTP.SYS 正确配置服务器证书。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。

证书未安装,并且它与 net tcp 绑定一起工作正常,我想我一定错过了一些小东西?

我注意到的一件事是 net.tcp 是双工通道,而基本 http 是单工通道,我确信设置有区别?例如,我需要在两端加载net.tcp的证书,那么基本的http会发生什么情况呢?

提前致谢

Lad*_*nka 4

WCF 配置中未配置 HTTPS 证书。您必须为 http.sys 配置证书。为此,请从命令行使用具有提升权限的netsh.exe 。如果您在 IIS/WAS 中托管服务,则不必使用 netsh,并且可以直接在 IIS 中配置 HTTPS