Search code examples
.netwindowswcfwmi

Binding an SSL certificate to a port programmatically


I'm working on a self-hosted WCF service for which encrypted communications is an option. Everything works fine when a certificate is already bound to the port as described here.

However, I want to avoid asking the user to run a command line tool. Is there a way the binding can be done programmatically? Perhaps using WMI?


Solution

  • I believe the way to create an HTTP.SYS namespace reservation is through the HttpSetServiceConfiguration() unmanaged API; so you'll need some P/Invoke for that. There's some sample code that might be useful in one of Keith Brown's MSDN columns.