<p>I've read this <a href="https://stackoverflow.com/questions/40122/exceptions-in-web-services">thread</a> for WCF has inbuilt Custom Fault codes and stuff.</p>

<p>But what is the best practice for <em>ASP.Net</em> web services? Do I throw exceptions and let the client handle the exception or send an Error code (success, failure etc) that the client would rely upon to do its processing.</p>

<p>Update: Just to discuss further in case of <em>SOAP</em>, let's say the client makes a <em>web svc</em> call which is supposed to be a notification message (no return value expected), so everything goes smooth and no exceptions are thrown by the svc. </p>

<p>Now how will the client know if the notification call has gotten lost due to a communication/network problem or something in between the server and the client? compare this with not having any exception thrown. Client might assume it's a success. But it's not. The call got lost somewhere.</p>

<p>Does send a 'success' error code ensures to the client that the call went smooth? is there any other way to achieve this or is the scenario above even possible?</p>

[{'answer_id': 78171, 'author': 'Sunny Milenov', 'author_id': 8220, 'author_profile': 'https://Stackoverflow.com/users/8220', 'pm_score': 1, 'selected': False, 'text': '<p>Depends on how you are going to consume the web service - i.e. which protocol are you going to use.</p>\n\n<p>If it is GET or POST, better return error code, as the calling HttpWebRequest (.Net) or other code will receive server error, and have to deal with it to extract the exception code.</p>\n\n<p>If it is SOAP - then it is perfectly ok to throw custom exceptions (you do not want to return internal framework exceptions, as they may reveal some stack trace, etc. to external parties).</p>\n\n<p>As the SOAP web services are exactly meant to look to the calling code as a normal method call, the corresponding calling framework should be able to handle and propagate the exception just fine, thus making the calling code look and behave as it deals with internal calls.</p>\n'}, {'answer_id': 91536, 'author': 'Paul van Brenk', 'author_id': 1837197, 'author_profile': 'https://Stackoverflow.com/users/1837197', 'pm_score': 3, 'selected': True, 'text': '<p>Jeff Atwood posted <a href="http://www.codinghorror.com/blog/archives/000054.html" rel="nofollow noreferrer">an interesting aerticle</a> about this subject some time ago. Allthough a .NET exception is converted to a SoapFault, which is compatible with most other toolkits, the information in the faults isn\'t very good. Therefor, the conlusion of the article is that .NET webservices don\'t throw very good exception messages and you should add additional information:</p>\n\n<pre><code>Private Sub WebServiceExceptionHandler(ByVal ex As Exception)\n    Dim ueh As New AspUnhandledExceptionHandler\n    ueh.HandleException(ex)\n\n    \'-- Build the detail element of the SOAP fault.\n    Dim doc As New System.Xml.XmlDocument\n    Dim node As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _\n        SoapException.DetailElementName.Name, _\n        SoapException.DetailElementName.Namespace)\n\n    \'-- append our error detail string to the SOAP detail element\n    Dim details As System.Xml.XmlNode = doc.CreateNode(XmlNodeType.Element, _\n        "ExceptionInfo", _\n        SoapException.DetailElementName.Namespace)\n    details.InnerText = ueh.ExceptionToString(ex)\n    node.AppendChild(details)\n\n    \'-- re-throw the exception so we can package additional info\n    Throw New SoapException("Unhandled Exception: " &amp; ex.Message, _\n        SoapException.ClientFaultCode, _\n        Context.Request.Url.ToString, node)\nEnd Sub\n</code></pre>\n\n<p>More info why soapfaults are better <a href="https://stackoverflow.com/questions/81306/wcf-faults-exceptions-versus-messages">in this question</a>.</p>\n'}]
['https://Stackoverflow.com/questions/78064', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1747/']