Best Practice to return responses from service
- by A9S6
I am writing a SOAP based ASP.NET Web Service having a number of methods to deal with Client objects. e.g:
int AddClient(Client c) = returns Client ID when successful
List GetClients()
Client GetClientInfo(int clientId)
In the above methods, the return value/object for each method corresponds to the "all good" scenario i.e. A client Id will be returned if AddClient was successful or a List< of Client objects will be returned by GetClients. But what if an error occurs, how do I convey the error message to the caller?
I was thinking of having a Response class:
Response { StatusCode, StatusMessage, Details }
where Details will hold the actual response but in that case the caller will have to cast the response every time.
What are your views on the above? Is there a better solution?
---------- UPDATED -----------
Is there something new in WCF for the above? What difference will it make If I change the ASP.NET Web Service to a WCF Service?