【发布时间】:2014-05-09 14:24:28
【问题描述】:
使用以下代码,我的服务在 http 上运行良好:
WebServiceHost serviceHost = new WebServiceHost(typeof(RestInterface), new Uri(http://localhost/rest));
serviceHost.Open();
当我尝试通过 https 托管完全相同的服务时,它不起作用。我在服务跟踪查看器中一无所获,Chrome 只是说“此网页不可用”。这是我用于 https 的代码:
var serviceHost = new WebServiceHost(typeof(RestInterface), new Uri(https://localhost/rest));
serviceHost.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
X509CertificateValidationMode.Custom;
serviceHost.Credentials.ClientCertificate.Authentication.CustomCertificateValidator =
new CertValidator(); // Custom validator that will accept any cert
serviceHost.Credentials.ServiceCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindBySubjectName,
"localhost");
var binding = new WebHttpBinding();
binding.Security.Mode = WebHttpSecurityMode.Transport;
var ep = serviceHost.AddServiceEndpoint(typeof(IRestInterface), binding, "");
ep.EndpointBehaviors.Add(new WebHttpBehavior());
serviceHost.Open();
有人搞定这个吗?我做错了什么?!?
【问题讨论】:
标签: .net web-services wcf rest c#-4.0