开发者

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.n开发者_开发知识库et development server doesn't support the https endpoint.


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"


I'm not certain that this is the best solution to your problem, but one way of doing this would be to declare in the config file a variable to indicate what environment this is running in (dev or prod). If you configure two endpoints, you could say in your hosting code,

if environment=="dev", then host the service on endpoint A.

if environment=="eval", then host the service on endpoint B.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜