Hello, I've started developing web service for a month now but have
come across a problem. What is the best way to return success,
failed, or exception message/string back to the client if they are
expecting different type (object, array, dataset, integer, etc) . for
example.
I have the services
login (returns a message string)
GetCusomers (returns as dataset)
addCustomer (returns an int)
updateCustomer (returns a message string)
when the use is logs in I want to supply them with a message
"login failed" or "login successful" but In ASP.net I'm used to just
returning a 1/0 or True/False to the calling function, checking for
the value and then displaying a message.
Now If I were accessing a webservice I would find it strange to code
against the message
If (sMessage = "login successful") THEN server.redirect(yadda yadda)
Is there any clean way of doing this?
What if I have a service that adds a record then returns an object of
that data (or just an ID for that record). How can I communicate a
string saying "add successful" if I'm already returning an object or
integer - the client can figure something out but I'm wanting to be
able to return status messages
thanks-
Ben Strackany - 14 Feb 2005 22:15 GMT
You can think of a web service as a normal function you can call. You can
return almost anything you want, it doesn't have to be a string. So in your
case your web server methods could return booleans or ints, or throw
exceptions w/ detailed error information. Ask yourself how you would code
the method if you weren't using a web service.
Calling a web service isn't *exactly* the same as calling a local method
(there are some exceptions, and you need to pay attention to the amount of
data going back & forth), but it's pretty easy to write clean, usable web
services in .net. Much easier than it was with ASP 3. :)
For more sophisticated error handling, I suggest you look into raising SOAP
exceptions from web services. MSDN has an article here
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconhandlingraisingexceptionsinxmlwebservices.asp) but you can search
the web for "C# web service exceptions" & find more information.
Good luck,
Ben Strackany
www.developmentnow.com
> Hello, I've started developing web service for a month now but have
> come across a problem. What is the best way to return success,
[quoted text clipped - 30 lines]
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------