views:

679

answers:

3

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?

A: 

Out of curiosity did you check to see if your fault was on the InnerException property?

(Sorry, no other ideas at the moment. I'm pretty green with regard to WCF.)

confusedGeek
InnerException is null. Thanks for the suggestion though :)
RandomNoob
+1  A: 

There is actually a collection that is present within the fault that has all the messages you are looking for:

foreach (ValidationDetail detail in fault.Detail.Details)
{
   ...
}
MattK
A: 

Found these details on the client catch... still would be nice if we could assign the error message