473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Server-Side Data Validation

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
Nov 23 '05 #1
2 1847

Hi Matt:
[WebMethod]
public bool IsValidProduct(int prod)
{
// return true if valid, false if not
}
This is good (if you don't want to pass a status message back).
[WebMethod]
public bool IsValidProduct(int prod, out string Error)
{
// return true if valid, false if not, and populate Error
// with meaningful string
}

Hmm... You won't be able to consume this web method from a VB.NET client
(you will have to use an initialized ByRef parameter). Also, you will need
to specify the SoapRpcMethod attribute with this web method, making it
non-conformant with WS-I Basic Profile 1.1

A better way is:

class Status
{
public bool isValid;
public string message;
}

public Status IsValidProduct (int productId)
{
//...
}
[WebMethod]
public void ValidateProduct(int prod)
{
// if product is not valid, raise exception
}


Don't use exceptions for program flow.

Hope this helps,
Mujtaba.
Nov 23 '05 #2
Mujtaba Syed wrote:
Hi Matt:
public bool IsValidProduct(int prod)
This is good (if you don't want to pass a status message back).


Yeah, but it's pretty useless to the end-user if I don't. Next ...
public bool IsValidProduct(int prod, out string Error)


Hmm... You won't be able to consume this web method from a VB.NET client
(you will have to use an initialized ByRef parameter). Also, you will need
to specify the SoapRpcMethod attribute with this web method, making it
non-conformant with WS-I Basic Profile 1.1


Sounds like work :) Next ...
A better way is:

class Status
{
public bool isValid;
public string message;
}

public Status IsValidProduct (int productId)


Ok, that sounds reasonable. Does the FCL define a type similar to your
'Status' example above for this sort of thing? It sounds like a common
enough task.
[WebMethod]
public void ValidateProduct(int prod)
{
// if product is not valid, raise exception
}

Don't use exceptions for program flow.


Yeah, I didn't like that last one either.

That said - it makes sense to raise an exception in the UpdateXXX method
if data is invalid, right? I mean, the UpdateXXX method *expects* valid
data - anything else has to be an exception.

Thanks for you reply!

Matt
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil | last post by:
I am using a Pascal like language (Wealth-Lab) on W2K and call this server: class HelloWorld: _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}" _reg_desc_ = "Python Test COM Server"...
9
by: Grim Reaper | last post by:
My work let me put SQL Server 7.0 Enterprise Edition on my laptop. I have never setup a server from the beginning, so I am a little new at creating server groups. Alright, I am trying to create...
0
by: Chris Halcrow | last post by:
Hi I've spent ALL DAY trying to re-install SQL Server 2000 on Windows XP. I continually get the error 'cannot configure server' just at the end of the installation. I've tried the following: ...
22
by: EP | last post by:
When running my asp.net hosting service (asp.net without IIS), on server 2003 with IIS not installed, I get the following when trying to process a request. "System.DllNotFoundException: Unable to...
14
by: Developer | last post by:
Hello All, i have recently installed VS2005 and was trying to install SQL sever 2000. I have Win XP' SP2. But when I tried installing, it only installed client tools and not the database. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.