Response action for undeclared faults in WCF Exception Handler

Topics: Exception Handling Application Block
Aug 2, 2007 at 7:35 AM
Unless you explicitly declare the fault contract type that you want your WCF Exception Handler to send back, you'll get an error on the server. This happens because the handler sets the response action to the incoming Request action. This will happen even if you have declared a parent class of the actual fault contract in the FaulContractAttribute. I looked at the code in ExceptionShieldingErrorHandler.GetFaultAction:
*********************************************************************************************
if (operation.Action.Equals(operationAction, StringComparison.InvariantCultureIgnoreCase))
{
foreach(FaultContractInfo fault in operation.FaultContractInfos)
{
if (fault.Detail == faultContractType)
{
return fault.Action;
}


}
}
}
return operationAction; // This is what causes the problem.
*********************************************************************************************
What should ideally happen is - if we can't find an exact match, we should check if a parent class of the fault contract has been declared and use that. If all else fails, we should fallback on the standard "http://www.w3.org/2005/08/addressing/soap/fault" - this is exactly what the WCF framework does today for undeclared fault types. So, the code should ideally be modified to look like this:
********************************************************************************************
if (operation.Action.Equals(operationAction, StringComparison.InvariantCultureIgnoreCase))
{
foreach(FaultContractInfo fault in operation.FaultContractInfos)
{
if (fault.Detail == faultContractType)
{
return fault.Action;
}

if (fault.Detail.IsAssignableFrom(faultContractType))
{
action = fault.Action;
}
}
}
}
if (action == null)//did not find contract type or it's parent class
return "http://www.w3.org/2005/08/addressing/soap/fault";
*********************************************************************************************

The only thing that stops me from doing this is because I want to avoid deviating from the standard framework code. Was kind of hoping that MS would consider this in the next version of the WCF Exception Handler!
Aug 2, 2007 at 11:41 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.