我已经创建了一个WCF HTTP
自我托管的网络服务。现在我想将其转换为HTTPS
。所以我遵循以下几点:无法运行WCF https网络服务
跟着this页面创建一个certificates
并将其绑定到一个特定的端口。 我使用mmc
- >console root
创建了一个证书,并遵循上面链接中写入的相同步骤。
然后我运行下面的命令端口绑定证书:
netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}
我根据我的证书更改certhash
。我也检查了Created certificate info
并得到了这个。
我也粘贴写在我的项目绑定端口上运行的Web服务的代码:
try
{
m_running = true;
private static String m_baseAddress = "https://10.0.0.1:8083";
WebHttpBinding _binding = new WebHttpBinding();
_binding.Security.Mode = WebHttpSecurityMode.Transport;
_binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
m_serviceHost = new WebServiceHost(typeof(TService), new Uri(m_serviceAddress));
m_serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName,"contoso.com");
ServiceEndpoint ep = m_serviceHost.AddServiceEndpoint(typeof(TContract), _binding, "");
m_serviceHost.Open();
}
catch(Exception e){ }
每当我重建我的项目并运行它。它总是开始一秒钟,然后停下来。我检查了日志并没有出现任何内容。
但是,当我删除了这条线
m_serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName,"contoso.com");
和替换https
到http
。它工作正常。
您仍在使用FindBySubjectName和“contoso.com”作为主题名称。这是你的证书中使用的名字吗? – 2013-02-20 21:36:37
在你的m_serviceHost.AddServiceEndpoint()中,你正在添加一个没有配置安全模式的新WebHttpBinding()。你应该使用之前创建的'绑定'。但是我仍然很惊讶你没有看到任何错误。此外,如果您继续看到问题,请尝试添加跟踪并查看您是否获得了更多信息。 – Praburaj 2013-02-20 23:45:57
@MortenMertner从哪里可以看到我的证书名称? – 2013-02-21 08:04:12