自托管WCF服务使用HTTP而不是HTTPS

时间:2013-08-05 12:43:19

标签: c# wcf

好的,我正在控制台应用程序中托管WCF服务。

所有绑定都是以编程方式创建的,因此没有配置设置。

我有一个工作服务,只要我使用HttpTransportBindingElement但是只要我使用HttpsTransportBindingElement然后什么都不起作用,服务就不会在浏览器中显示而客户端应用程序返回{{1 }}

我已尝试将405 (Method Not Allowed) CommunicationException设置为SecurityBindingElement,但我不确定应该使用哪种选项。

CustomBinding

SecurityBindingElement.CreateCertificateOverTransportBindingElement()

创建主机的代码在

之下
SecurityBindingElement.CreateAnonymousForCertificateBindingElement()

1 个答案:

答案 0 :(得分:6)

我关注此博客http://blogs.msdn.com/b/james_osbornes_blog/archive/2010/12/10/selfhosting-a-wcf-service-over-https.aspx,其中强调为了使HTTPS正常工作,您需要将端口绑定到您正在使用的证书。

Process bindPortToCertificate = new Process(); bindPortToCertificate.StartInfo.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "netsh.exe");

bindPortToCertificate.StartInfo.Arguments = string.Format("http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={{{2}}}", port, certificate.Thumbprint, Guid.NewGuid());

bindPortToCertificate.Start();

bindPortToCertificate.WaitForExit();

一旦完成,一切都有效。

如果有任何需要我的示例代码,请与我联系,以设置和配置以编程方式设置的绑定的自托管WCF服务器。 :)

相关问题