Problem:
I have a WCF Webservice which can be used by customers to upload multiple datarecords. To validate the data I use Enterprise Library Validation Block. The records can be nested several layers deep.
Question:
How to identify in which record the validation failed?
Example:
Consider the following datastructure. For each Continent there can be multible Countries and for each Country there can be multiple Cities.
- Continent
- Name
- Country
- Name
- City
- Name
- Mayor
When the validation of the Mayor of a City fails, I want to know for which City, Country and Continet it failed.
I Solved my problem by doing the following:
Setup int the WCF Integration:
(Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF)Create a simple marker Attribute:
which will be put on the Property that identifies the data record.
Create an Interface:
This is for the reference from the City record to the Country record in the above example so that all Identifiers up the chain also get included
Modify the
BeforeCall()Method inValidationParameterInspectorto crawl all inputs and set the
BackReferenceusing something like this:Modify the
CreateValidationDetailmethod inValidationParameterInspectorto go up the record tree via the BackReferences with something like this
and put it into the
Details.Keyof theValidationKDetail. So far the Setup.In the Webservice
all you have to do now is Implement the
IValidationBackReferenceinterface on the classes used by the Webservice and put the[ValidationKey]Attribute on appropriate Properties.The example above would look like:
what a monster …