【发布时间】:2013-08-05 12:43:18
【问题描述】:
好的,我在控制台应用程序中托管 WCF 服务。
所有绑定都是以编程方式创建的,因此没有配置设置。
只要我使用HttpTransportBindingElement,我就有一个可用的服务,但是一旦我使用HttpsTransportBindingElement,就没有任何效果,该服务不会显示在浏览器中,并且客户端应用程序会返回一个405 (Method Not Allowed) CommunicationException
我尝试将SecurityBindingElement 设置为我的CustomBinding,但我不确定应该使用哪个选项。
SecurityBindingElement.CreateCertificateOverTransportBindingElement()
SecurityBindingElement.CreateAnonymousForCertificateBindingElement()
等等
创建主机的代码如下
baseAddress = new Uri(string.Format("{0}://{1}", strConnectionType, ConfigurationManager.AppSettings["baseAddress"]));
ServiceHost host = new ServiceHost(typeof(IMyService), baseAddress);
host.AddServiceEndpoint(typeof(MyService), binding, String.Empty);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpsGetEnabled = certificate != null;
smb.HttpGetEnabled = certificate == null;
host.Description.Behaviors.Add(smb);
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
if (sdb == null)
{
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else
{
if (!sdb.IncludeExceptionDetailInFaults)
{
sdb.IncludeExceptionDetailInFaults = true;
}
}
if (certificate != null)
{
host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, certificate.Thumbprint);
}
【问题讨论】:
-
什么是
binding? WCF 服务的编程配置也太难了,为什么不使用配置文件呢? -
@ta.speot.is 你能详细说明你的问题吗?
-
@shankar-damodaran 感谢您的编辑 :)
-
@ta.speot.is 因为我很特别与未正确配置的安全元素有关。