I am looking to place attributes on my WCF data contract members to validate string length and possibly use regex for more granular parameter validation.
I can the [Range] attribute for numeric and DateTime values and was wondering if any of you have found any other WCF Data Member attributes I can use for data validation. I have found a bevvy of attributes for Silverlight but not for WCF.
Manually Validating Values: You can manually apply the validation test by using the Validator class. You can call the ValidateProperty method on the set accessor of a property to check the value against the validation attributes for the property. You must also set both ValidatesOnExceptions and NotifyOnValidationError properties to true when data binding to receive validation exceptions from validation attributes.
Contact class:
Add
System.ComponentModel.DataAnnotations
reference to your project.The reference provides some DataAnnotations which are:
RequiredAttribute, RangeAttribute, StringLengthAttribute, RegularExpressionAttribute
you can in your datacontract like below.
Hope this helps.
Try to look look for WCF Data Annotations. WCFDataAnnotations allows you to automatically validate WCF service operation arguments using System.ComponentModel.DataAnnotations attributes.
http://wcfdataannotations.codeplex.com/