I am working on a .net 3.5 REST WCF application.
I’ve found WebFaultException is the best way to handle errors in REST services.
I can’t seem to find the WebFaultException class in .net 3.5.
Was it introduced in .net 4 or am I missing a namespace import?
Is there a work around that implements WebFaultException behavior in .net 3.5?
I appreciate your help.
I am working on a .net 3.5 REST WCF application. I’ve found WebFaultException is
Share
It’s true,
WebFaultExceptionwas only introduced in the .NET 4.0 timeframe. Before that you were responsible for setting all of the HTTP properties on theWebOperationContext.Current.OutgoingResponseand handling failure control flow yourself rather than relying on throwing exceptions.That said, you can create your own
WebFaultExceptionclass in 3.5 and then implement a WCFIErrorHandlerthat generically retrieves the HTTP information off your customWebFaultExceptionclass and transfers them to the various properties of theWebOperationContext.Current.OutgoingResponseand creates aMessageinstance for the body (if any) in theProvideFaultimplementation.