I’m designing a WCF service that will return a response code (such as 0 for success, or another number for errors). Also, all methods of the web service will perform several common validations (such as authenticating an apiKey).
I am wondering if there is a best practice approach or organizing and retrieving these response codes and messages.
Thanks for any suggestions.
Ideally, don’t use response codes. Return something usable on success (or void) and throw an exception on failure.
People deal with exceptions. We often forget to look at returned codes, especially when 99% of the time it’s success, and we don’t care about any response. So we don’t capture. Then we don’t bother checking for failure. Then we spend 2 days tracking down a bug that we can’t find because no exception was thrown and we have no idea where the 600,000 line application failed that used your webservice… we don’t even know it was a call to your webservice that failed. Just that some data is wrong for some unknown reason.
There’s a topic on SO about this: Which and Why do you prefer Exceptions or Return Codes