Validating WCF with lists

Topics: Validation Application Block
Sep 7, 2007 at 6:54 AM
How would you validate a WCF data contract that contains a list with key value pairs where the data has to be validated differently based on a key?
For example, here is very reasonable scenario. Let's say there is a list of
public class ContactInfo
public string ContactType;
public string ContactValue;
If ContactType is "EMAIL" than ContactValue contains an email address, but if ContactType is "PHONE" than ContactValue contains a phone number etc., and therefore must be validated differently.
I can solve this problem when data is collected in ASP.NET page by creating distinct Rule Sets, one for EMAIL and the other one for PHONE, so my PropertyProxyValidators just points to the correct Rule Set.

However, once the WCF contract is created and passed to the service the requirement is to validate again at the service. How would you do that? The list now contains both EMAIL and PHONE, so you cannot apply one RuleSet without violaing the other. Am I missing something?

Alex K.