Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF faults and exceptions
    text
    copied!<p>I'm writing a WCF service for the first time. The service and all of its clients (at least for now) are written in C#. The service has to do a lot of input validation on the data it gets passed, so I need to have some way to indicate invalid data back to the client. I've been reading a lot about faults and exceptions, wrapping exceptions in faults, and a lot of conflicting articles that are just confusing me further. What is the proper way to handle this case? </p> <p>Should I avoid exceptions altogether and package a Results return message? Should I create a special Fault, or a special Exception, or just throw ArgumentExceptions like I would for a non-WCF validation function?</p> <p>The code I have right now (influenced by <a href="http://msdn.microsoft.com/en-us/library/ms733841.aspx" rel="noreferrer">MSDN</a>) is:</p> <pre><code>[DataContract] public class ValidationFault { [DataMember] public Dictionary&lt;string, string&gt; Errors { get; private set; } [DataMember] public bool Fatal { get; private set; } [DataMember] public Guid SeriesIdentifier { get; private set; } public ValidationFault(Guid id, string argument, string error, bool fatal) { SeriesIdentifier = id; Errors = new Dictionary&lt;string, string&gt; {{argument, error}}; Fatal = fatal; } public void AddError(string argument, string error, bool fatal) { Errors.Add(argument, error); Fatal |= fatal; } } </code></pre> <p>And on the method there's [FaultContract(typeof(ValidationFault))]. So is this the "right" way to approach this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload