我有 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;
在客户端:
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);
但是当连接时,我收到此错误
异常 - 发生错误
发出 HTTP 请求https://localhost/MyService https://localhost/MyService。这
可能是因为
服务器证书未配置
正确使用 HTTPS 中的 HTTP.SYS
案件。这也可能是由
安全绑定不匹配
客户端和服务器之间。
证书未安装,并且它与 net tcp 绑定一起工作正常,我想我一定错过了一些小东西?
我注意到的一件事是 net.tcp 是双工通道,而基本 http 是单工通道,我确信设置有区别?例如,我需要在两端加载net.tcp的证书,那么基本的http会发生什么情况呢?
提前致谢
WCF 配置中未配置 HTTPS 证书。您必须为 http.sys 配置证书。要做到这一点,请使用执行程序 http://msdn.microsoft.com/en-us/library/ms733791.aspx从具有提升权限的命令行。如果您在 IIS/WAS 中托管服务,则不必使用 netsh,您可以直接在 IIS 中配置 HTTPS http://learn.iis.net/page.aspx/144/how-to-set-up-ssl-on-iis-7/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)