Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / February 2005

Tip: Looking for answers? Try searching our database.

best way to return error/success messages to client?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
b - 10 Feb 2005 19:53 GMT
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 **
> ----------------------------------------------------------

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.