WCF & EntLib’s Validation Application Block MessageContract Caveat

I’ve seen some blog entries of people having trouble using VAB in WCF when a web service has a message contract. Apparently any contained DataContracts aren’t validated.

After some fidgeting I found the problem: apparently the validation starts at the MessageContract. Just decorate the message body property (decorated with [MessageBody]) with [ObjectValidator].

The ObjectValidator is a validator that allows you to validate properties of a class containing properties decorated with validators. In other words; it allows validation of subtypes.

Advertisements

One thought on “WCF & EntLib’s Validation Application Block MessageContract Caveat

  1. Hello,
     
    Excuse me for barking in but I\’ve been lost with WCF and Validation Block for the past 10 days. And I would like some help if you can. I have an operation contract which takes as input a datacontract with lets say 2 datamembers of type string. I am trying to apply StringthLengthValidator attribute. My question is how do I inform the client if for example the length is too big?? I have <FaultContract(typeof(myFaultException))> on my OperationContract but when I am building I get an error and it suggests
    <FaultContract(typeof(PerseusFaultEx)Is )> I\’m lost. Any sugestions?? I\’have readen every website that has *msdn*
    Thank you.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s