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.
It's true, WebFaultException was only introduced in the .NET 4.0 timeframe. Before that you were responsible for setting all of the HTTP properties on the WebOperationContext.Current.OutgoingResponse and handling failure control flow yourself rather than relying on throwing exceptions.
That said, you can create your own WebFaultException class in 3.5 and then implement a WCF IErrorHandler that generically retrieves the HTTP information off your custom WebFaultException class and transfers them to the various properties of the WebOperationContext.Current.OutgoingResponse and creates a Message instance for the body (if any) in the ProvideFault implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With