Validation of Non-trivial RequestMessages with WCF

Topics: Validation Application Block
May 1, 2009 at 7:05 PM

We have set up the validation block with WCF integration and it is working for basic scenarios.

We have an UpdateUserRequest that gets validated; This object has 2 properties, Email and Details. 
We are able to validate that these properties are not null and that the Email property matches a regEx.

On the Details object, we have a property that is a list of strings. What we can't seem to figure out is how to validate that the list of strings is not null.

We've added a type entry in the validation config for the Details type, but it doesn't seem to be applied to the instance that is in UpdateUserRequest.

Can this be done via config or are we forced to attribute the classes themselves?



On a side note, it seems like the EntLib config Editor doesn't like it when you use resources for the pattern property of a regEx. The doc says you must not specify pattern if you use resource, but the editor reports that its an error to not have the pattern property set.

May 4, 2009 at 4:06 AM
You can use the ObjectCollectionValidator but you're gonna have to wrap your strings into a class.  
ObjectCollectionValidator -

Regarding the Regex Pattern property, I'll be logging an issue for that, (if you haven't already).

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
May 4, 2009 at 12:57 PM
I'm not sure how to interpret your response.

My List<string> property is not a top level property on the request message (MyReq.StringList), it is a sub property of a property : MyReq.Details.StringList

We have a not null validator on the Details object, but haven't figured out how to configure the validation so that it targets the properties of details.

May 4, 2009 at 2:21 PM
Sorry, forgot that detail.  Use the ObjectValidator for the Details property.  Using it causes all validators for your Detail property to be invoked.  If you used an objectcollectionvalidator for the Detail's list property, it will be trigerred when you validate your MyRequest.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
May 4, 2009 at 5:54 PM
Thanks, thats the trick we were looking for.