Best Practice to return responses from service

Posted by A9S6 on Programmers See other posts from Programmers or by A9S6
Published on 2011-03-08T16:09:44Z Indexed on 2014/06/01 21:55 UTC
Read the original article Hit count: 208

Filed under:

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?

© Programmers or respective owner

Related posts about c#