gpt4 book ai didi

wcf - BasicHttpBinding 使用传输安全和自签名证书

转载 作者:太空宇宙 更新时间:2023-11-03 12:48:36 27 4
gpt4 key购买 nike

我有 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);

但是当连接时,我得到了这个错误

Exception - An error occurred while making the HTTP request to https://localhost/MyService. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.

没有安装证书,但它在 net tcp 绑定(bind)上运行良好,我想我一定是漏掉了一些小东西?

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

提前致谢

最佳答案

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

关于wcf - BasicHttpBinding 使用传输安全和自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5739780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com