WCF ExceptionShielding and non generic FaultContract

Topics: Exception Handling Application Block
Jan 4, 2012 at 3:13 PM

      <add name="Policy">
          <add type="System.InvalidOperationException, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException" name="InvalidOperationException">
              <add exceptionMessage="Test" faultContractType="System.ServiceModel.FaultException, System.ServiceModel"
                type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                name="Fault Contract Exception Handler">

Exception thrown :"No signature message parts were specified for messages with the 'urn:ServiceContract.Method' action"
Is there any way to make it work? I tried using custom generic fault contract  and it works fine, but it will mean that I will have to add FaultContract attribute to few hundred operations (I heard that Microsoft will add option to add fault contract on service level, but even based on connect http://connect.microsoft.com/VisualStudio/feedback/details/343148/allow-faultcontractattribute-to-be-specified-on-a-servicecontract-interface
 it should be implemented in 4.0 I dont see any documentation for it http://msdn.microsoft.com/en-us/library/ms752208.aspx)  and make sure that all new ones are including it and we use WSSF which will mean that I will have to do it in all service models which sounds like a nightmare.

I know that other idea is to create Operation Invoker and add it as custom behavior to all services, but this is something custom and I would prefer to use known standards:

 public object Invoke(object instance, object[] inputs, out object[] outputs)
            OperationContext context = OperationContext.Current;
                return this.invoker.Invoke(instance, inputs,out outputs);
            catch(Exception ex)
                throw new FaultException(ex.Message);

 I don't want to use includeExceptionInFaults because I want to have diffent messages based on type of exeption and log it  for some types and others not - Exception Application Block seem perfect for it I just want to know if I can throw default non generic FaultContract.

Jan 5, 2012 at 2:27 AM

I don't think this is possible out of the box.  See this entry from the issue log for an issue around this approach and a workaround.  You could look at modifying the source code as mentioned to create the behavior you are looking for.   The downside is that it would involve a rebuild of the block.

Randy Levy
Enterprise Library support engineer

Jan 5, 2012 at 2:41 PM
Edited Jan 5, 2012 at 2:43 PM

I cannot propose that solution to my client that they should fix the framework and have their custom entlib....

Anyway Thank You Randy for finding work item related to it. I will probably go with custom behavior at this point. It will not be configurable using config file which means that it will be the same for each environment but I think my client will have to just deal with - it will be still centralized solution to handle all exceptions for all services in one place.