I posted some Bits Michael and I wrote recently in a WCF Project:

The Constraints-Extensions let you easily define attribute based limitations for input, output and return parameters. Limitations can be set to service contracts operations as well as to data contract data member implementations. The constraints validation gets called at runtime by the WCF infrastructure and the behavior will throw a ConstraintViolationException with descriptive messages in case of a constraint gets violated/the validation fails.

The following constraint attributes have been implemented:

  • Between
  • BetweenExclusive
  • CompareAgainst
  • EarlierThanNow
  • EarlierThanToday
  • EqualTo
  • GreaterEqualTo
  • GreaterThan
  • LaterThanNow
  • LaterThanToday
  • LessEqualTo
  • LessThan
  • Match
  • MaxElements
  • MaxLength
  • MinElements
  • MinLength
  • NotBetween
  • NotEmpty
  • NotEqualTo
  • NotNull
  • Nullable
  • OneOff

Data Contract Sample:

class TestClass  
    [LessEqualTo(CompareAgainst.FieldOrProperty,<span style="color: maroon;">"EndDate")]  
    DateTime StartDate;

    [GreaterEqualTo(CompareAgainst.FieldOrProperty, <span style="color: maroon;">"StartDate")]  
    DateTime EndDate;

    public TestClass(DateTime startDate, DateTime endDate)  
        StartDate = startDate;  
        EndDate = endDate;  


Service Contract Sample:

[ServiceContract, ConstraintsValidatorBehavior]  
interface ITestConstraints  

    int MethodA(  
        int a,   
        double b,   
        string c); 

    int MethodB(  
        [Between(0, 100)]   
        int a,   
        ref double b,   
        out string c);

    DateTime MethodC(  
        int a);

    void MethodD(  
        TestClass a);  

Download at wcf.netfx3.com