My advice:

1. Create schema files for each type of response XML that you receive
from the Service methods. When you get a response, validate the XML
against the Schema to determine if it matches expected format/content.
I would consider this as first level input validation the way you
would validate the Model in an MVC scenario.

2.  Next, create a library of functions (the example you provide is
simplistic but in the right direction) whose sole job is to validate
if a passed parameter is valid according to an optionally passed type.
Now this could turn out to be a time consuming task as there could be
an almost infinite number of validations that you wish to apply. (It's
easy to go overboard with validation, trust me!) You might find it
worthwhile to check out the M$ Validation Application Block (part of
the Enterprise Library - http://msdn.microsoft.com/en-us/library/dd203099.aspx)
for this purpose. This validation library should be called from the
property setters within your DTO.

3. If your DTO's reach the database at some later stage, you should
also implement constraint based validation in the database.

IMHO, it's best to validate in all layers. However, the intensity of
validation should differ and be strongest in the BLL.

On Mar 19, 9:48 am, rbr <[email protected]> wrote:
> Hello,
>
> I am looking for a solution for data validation other than forms
> validation. I am consuming a number of web services and then map the
> XML messages to a DTO. I would like to create a data validation
> library that will work across the services. I envision static
> functions like the following:
>
> IsValidString(string) - not empty, not sqlinjection/cross-site, etc.
>
> IsAlpha(string) - Only contains alpha characters
>
> IsNumeric(string) - Only contains numeric characters
>
> IsValidEnum(string, enum) - value is within given enum
>
> Etc, etc. I have tried to find good examples of best practices for
> this kind of validation online. however, all I seem to find are
> examples for forms validation. I was hoping for a P & P article or
> Application block but could not find either.
>
> If anybody has any advice or knows of any good articles I would
> greatly appreciate it.
>
> Thanks in advance!
>
> Ryan

Reply via email to