WCF – Faults / Exceptions versus Messages

This however carries overhead as throwing exceptions in .NET can be quite costly.

You’re serializing and de-serializing objects to XML and sending them over a slow network.. the overhead from throwing an exception is negligable compared to that.

I usually stick to throwing exceptions, since they clearly communicate something went wrong and all webservice toolkits have a good way of handling them.

In your sample I would throw an UnauthorizedAccessException with the message “Account Locked”.

Clarification: The .NET wcf services translate exceptions to FaultContracts by default, but you can change this behaviour. MSDN:Specifying and Handling Faults in Contracts and Services

Leave a Comment