WCF: Automatically disable MEX from DEBUG to RELEASE builds in VS2010?
I have code that automatically disbles fault information from flowing to clients when a RELEASE build of our product in installed. I am wondering whether there is a clever way that we can also disable MEX metadata from being available in our RELEASE build. Here is what I've done to automatically disable fault information, whic开发者_StackOverflow中文版h I found at the following link: http://codeidol.com/csharp/wcf/Faults/Fault-Contracts/.
// Enables exceptions to flow to clients when built for debugging;
// Otherwise, no details go to client.
public static class DebugHelper
{
public const bool IncludeExceptionDetailInFaults =
#if DEBUG
true;
#else
false;
#endif
}
// This service is singleton. If other calls arrive while one is in progress,
// they are queued.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Single,
IncludeExceptionDetailInFaults = DebugHelper.IncludeExceptionDetailInFaults)]
public class OurService : IOurService
If you configure your WCF service using a config file, then you could just have two separate configs - one for debug, one for release without the MEX endpoint.
You should add the mex endpoint in code and thus compile it away
精彩评论