Hi gang,
I have a web service class I'm developing along the same lines as that
described here in MSDN:
http://tinyurl.com/63sl4
http://msdn.microsoft.com/library/en...alkthrough.asp
That is, it has a GetXXX method that returns a dataset, and an UpdateXXX
method that takes a dataset and applies it to the database.
Works fine so far. I'm very happy.
However, one thing I'd like to do is some validation of individual
fields at the server side before the entire dataset is posted back.
For example, if my web service was to manage purchase orders, it would
be nice to ask my web service if a particular product was available to
order before I hit OK on my 'new order' form.
I guess my first instinct was, "Why not just pull down all the valid
products as another dataset and validate the entered product# against
them?"
That works fine for small datasets, but what if there are a million
active products? I'd much prefer to write an IsValidProduct webmethod
and be able to call that just after the user enters the product number.
How are others implementing validation like this? Should the method be:
[WebMethod]
public bool IsValidProduct(int prod)
{
// return true if valid, false if not
}
or
[WebMethod]
public bool IsValidProduct(int prod, out string Error)
{
// return true if valid, false if not, and populate Error
// with meaningful string
}
or
[WebMethod]
public void ValidateProduct(int prod)
{
// if product is not valid, raise exception
}
Any pointers?
Thanks,
Matt