Ok, so I host the WCF service in a console application.
all bindings are created programmatically, so no configuration settings.
I have a working service, if I use HttpTransportBindingElement , but as soon as I use HttpsTransportBindingElement then nothing works, the service does not appear in the browser, and the client application returns 405 (Method Not Allowed) CommunicationException
I tried setting SecurityBindingElement to my CustomBinding , but I'm not sure which option I should use.
SecurityBindingElement.CreateCertificateOverTransportBindingElement()
SecurityBindingElement.CreateAnonymousForCertificateBindingElement()
and etc.
Code for creating a host below
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); }
c # wcf
Secret squirrel
source share