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?
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?
The code I have right now (influenced by MSDN) is:
[DataContract]
public class ValidationFault
{
[DataMember]
public Dictionary<string, string> 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<string, string> {{argument, error}};
Fatal = fatal;
}
public void AddError(string argument, string error, bool fatal)
{
Errors.Add(argument, error);
Fatal |= fatal;
}
}
And on the method there's [FaultContract(typeof(ValidationFault))]. So is this the "right" way to approach this?