VAB with WCF hosted in IIS

Topics: Validation Application Block
Jun 18, 2008 at 8:10 AM
Is anyone actually using the VAB to validate request messages and data contracts on the server side, where the WCF services are hosted in IIS?

I have spent about 3 days trying to get this worked out, using configuration AND also using attributes.  Still no dice.

"According to the documentation"....
All I have to do is
1. add a behaviorExtension for the validation element in the config file
2. add an endpoint behavior element that contains the validation element with the attribute set to true
3. create a service endpoint whose behaviorConfiguration element is pointed to the named endpoint behavior created in step 2
4. decorate my OperationContract with the [FaultContract(typeOf(ValidationFault))] attribute
5. define my validation rules for the type that I want to validate

Am I missing something in my paraphrasing of the implementation details?


Notes about my environment...
-- I write services and dont trust the consumer of my services to do validation, this rules out using VAB for Client Side Validation.
-- Often times, QA defines the validation rules after my contract is already published to IIS.  In addition, I do contract first development, so I dont beleive that I should have to re-compile a data contract when validation rules change, so using attributes to validate members of a data contract is a moot point.
-- For 99% of all my service operations I pass types that are decorated with the [MessageContract] attribute.  The messages have [MessageBody] members for types that are decorated with [DataContract].  I do this because I need to control the message header and extra information.

Has anyone else had any issues while running the VAB with WCF services hosted in IIS?

Regards




 

Jun 18, 2008 at 4:17 PM

Hi,

I've just tried with EntLib 4 and had no problems; just make sure the ruleset in your validation endpoint behavior matches the ruleset in your rules. This could get tricky if you want to use different rules for different methods. In that case, you can use the [ObjectValidator("some rule set")] instead like this (using the template service when creating a WCF service project in VS 2008)

   13     [ServiceContract]

   14     public interface IService1

   15     {

   16 

   17         [OperationContract]

   18         [FaultContract(typeof(ValidationFault))]

   19         string GetData(

   20             [ObjectValidator("IService1.GetData")]

   21             int value);

   22 

   23         [OperationContract]

   24         CompositeType GetDataUsingDataContract(CompositeType composite);

   25     }

And the matching validation configuration is

   26   <validation>

   27     <type assemblyName="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

   28       name="System.Int32">

   29       <ruleset name="IService1.GetData">

   30         <validator lowerBound="2" lowerBoundType="Inclusive" upperBound="5"

   31           upperBoundType="Inclusive" negated="false" messageTemplate=""

   32           messageTemplateResourceName="" messageTemplateResourceType=""

   33           tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

   34           name="Range Validator" />

   35       </ruleset>

   36     </type>

   37   </validation>

Now, your question is about VAB for a service hosted in IIS; does this imply that when you host your WCF service differently you get the expected result?

Fernando


DevilDog74 wrote:
Is anyone actually using the VAB to validate request messages and data contracts on the server side, where the WCF services are hosted in IIS?

I have spent about 3 days trying to get this worked out, using configuration AND also using attributes.  Still no dice.

"According to the documentation"....
All I have to do is
1. add a behaviorExtension for the validation element in the config file
2. add an endpoint behavior element that contains the validation element with the attribute set to true
3. create a service endpoint whose behaviorConfiguration element is pointed to the named endpoint behavior created in step 2
4. decorate my OperationContract with the [FaultContract(typeOf(ValidationFault))] attribute
5. define my validation rules for the type that I want to validate

Am I missing something in my paraphrasing of the implementation details?


Notes about my environment...
-- I write services and dont trust the consumer of my services to do validation, this rules out using VAB for Client Side Validation.
-- Often times, QA defines the validation rules after my contract is already published to IIS.  In addition, I do contract first development, so I dont beleive that I should have to re-compile a data contract when validation rules change, so using attributes to validate members of a data contract is a moot point.
-- For 99% of all my service operations I pass types that are decorated with the [MessageContract] attribute.  The messages have [MessageBody] members for types that are decorated with [DataContract].  I do this because I need to control the message header and extra information.

Has anyone else had any issues while running the VAB with WCF services hosted in IIS?

Regards