How to set ServiceHostingEnvironment.AspNetCompatibilityEnabled = true in Code (not in config) .NET/C#

前端 未结 5 1693
南笙
南笙 2021-02-03 11:09

I have a requirement to access the HttpContext.Current from with-in a RESTful WCF service. I know I am able to achieve this by adding the following to config:

&         


        
5条回答
  •  情深已故
    2021-02-03 11:45

    Consider factoring out the explicit use of HttpContext.Current behind an interface that you can stub out during unit testing.

    HttpContext.Current is only defined when your wcf service is hosted within an asp.net web application anyway - if some day you need to host it as an ordinary wcf service, HttpContext.Current is not going to be available.

提交回复
热议问题