问题
I have been looking in the MSDN docs but have not found a concrete answer.
Does the Debug property in @ServiceHost override the Web.config's compilation attribute or does the the web.config attribute override all?
Thanks.
回答1:
According to: http://msdn.microsoft.com/en-us/library/aa702682.aspx
The ASP.NET HTTP runtime handles ASP.NET requests but does not participate in the processing of requests destined for WCF services, even though these services are hosted in the same AppDomain as is the ASP.NET content. Instead, the WCF Service Model intercepts messages addressed to WCF services and routes them through the WCF transport/channel stack.
Unless you are running your services in WCF’s ASP.NET compatibility mode. In that case...
Unlike the default side-by-side configuration, where the WCF hosting infrastructure intercepts WCF messages and routes them out of the HTTP pipeline, WCF services running in ASP.NET Compatibility Mode participate fully in the ASP.NET HTTP request lifecycle. In compatibility mode, WCF services use the HTTP pipeline through an IHttpHandler implementation, similar to the way requests for ASPX pages and ASMX Web services are handled.
If we accept this assertion than we know that configuration inheritance should be respected.
If you wanted to be sure you could probably set up a test...
WCF services running in ASP.NET Compatibility Mode can access HttpContext.Current and its associated state. That means that you could interrogate the IsDebuggingEnabled property to see if you are in debug mode. You could also use some compiler directives like #if DEBUG to see if a block of code is reached.
I'd be very curious to hear what the ultimate verdict is. I think the key to this questions is whether or not this is a WCF service that is hosted in IIS and whether or not it is running in AspCompatibility mode.
来源:https://stackoverflow.com/questions/8362603/wcf-servicehost-debug-true-but-web-config-compilation-false