WCF ValidationFault

Posted by RandomNoob on Stack Overflow See other posts from Stack Overflow or by RandomNoob
Published on 2009-01-16T22:02:09Z Indexed on 2010/04/30 18:27 UTC
Read the original article Hit count: 750

I'm using Validation Application Block - Enterprise Library to validate parameters sent to my WCF Service operations. For instance, a certain operation requires the parameter to either be a 1 or 6, like so:

[OperationContract(Name="GetEmployeesByRegion")]
[FaultContract(typeof(ValidationFault))]
List<Employees> GetEmployeesByRegion([DomainValidator(1,6)]int regionId);

This works just fine i.e the validation fault occurs however, when the service is invoked by the client, a generic System.ServiceModel.FaultException is thrown. An the message indicates: "The creator of this fault did not specify a reason."

Now, I could check the parameters myself before the service cal and throw a custom fault but that seems to defeat the purpose of attribute based validation of parameters using the Validation Application Block. Is there anyway to customize the error returned by the validation Fault? It is also possible I'm doing something completely wrong. I just want the caller to know that he/she should have passed in a 1 or 6 in the exception message. Is this possible?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about wcf-faults