Search code examples
c#wcfendpoints

WCF HTTPS and HTTP bindings with single web.config


Is there any way I can accomplish the following:

Single Web.config file for a .net web application. the web application exposes a number of WCF services for consumption by javascript.

Production requires ssl, so all these services are forced over ssl.

Development does not allow ssl, (ASP.NET development server)

How can I configure this so that production will utilize an HTTPS endpoint, and development will utilize an HTTP endpoint for the same service?

Adding two endpoints to the same service doesn't work, because when it tries to connect to the HTTP endpoint it throws an error since the asp.net development server doesn't support the https endpoint.


Solution

  • I solved this by using a ServiceHostFactory to generate the appropriate bindings for me.

    It was a little awkward at first, having less control, but works out better in the end.

    this is the line that was key, I put it in my .svc file:

    Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"