Exception handler with wcf is not working in enterprise library 5.0

Topics: Exception Handling Application Block
Sep 19, 2012 at 10:35 AM
WCF Service: 
    public interface IService1
        string GetData(int value);
        // TODO: Add your service operations here
    public class WeGoofedDetails
        public string Message;
        public Guid ErrorID;

    public class Service1 : IService1
        public string GetData(int value)
            throw new Exception("I broke the code!");

<?xml version="1.0"?>
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
      <add name="Policy">
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
              <add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                exceptionMessageResourceType="" exceptionMessage="Oops" faultContractType="WcfService1.WeGoofedDetails, WcfService1, Version=, Culture=neutral, PublicKeyToken=null"
                name="Fault Contract Exception Handler">
                  <add source="{Guid}" name="ErrorID" />
    <compilation debug="true" targetFramework="4.0" />
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>

class Program
        static void Main(string[] args)
                Service1Client proxy = new Service1Client();
                var output = proxy.GetData(7);
            catch (FaultException<WeGoofedDetails> ex)
            catch (Exception ex)

Its always getting caught in 

catch (Exception ex)
instead of faultexception.

Any suggestion on this.
Sep 20, 2012 at 5:44 AM

Thanks for posting a full set of code and configuration for your issue.

I copied all of your code and configuration into a new project and it is working OK.  What exception are you getting instead of FaultException?

I would recommend Configuring Tracing for WCF and see if that gives you any additional information:

            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
               <add name="traceListener" 
                   initializeData= "c:\log\Traces.svclog" />

You could also download the WCF Exception Shielding With Logging Exception Handler Sample Project to compare.

Randy Levy
Enterprise Library support engineer