Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning Error Details from AJAX-Enabled WCF Service
    text
    copied!<p><strong>Short Version:</strong> Is there a/what is the suggested way to return error details to the client when an exception is thrown in an AJAX-Enabled WCF Service (aside from just throwing the gates open and sending back all of the exception details)?</p> <p><strong>Long Version:</strong></p> <p>I've got a relatively simple AJAX-enabled WCF service that I'm calling from the client using the default service proxy. I've provided code snippets below, but I do not believe there is anything wrong with the code per se.</p> <p>My problem is that if I throw an exception in the service, the error object returned to the client is always generic:</p> <pre><code>{ "ExceptionDetail":null, "ExceptionType":null, "Message":"The server was unable to process the request..." "StackTrace":null } </code></pre> <p>Ideally I would like to display different error messages on the client depending on what went wrong.</p> <p>One option is to allow exceptions in WCF faults, which would provide me with the full stack trace and everything, but I appreciate the security concerns with this, and that's actually a lot more information than I need. I could make do with just being able to send back a string describing the problem or something, but I don't see a way to do this.</p> <p>My Service Code:</p> <pre><code>[ServiceContract(Namespace = "MyNamespace")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class MyService { [OperationContract] public void DoStuff(string param1, string etc) { //Do some stuff that maybe causes an exception } } </code></pre> <p>On the client:</p> <pre><code>MyNamespace.MyService.DoStuff( param1, etc, function() { alert("success"); }, HandleError); </code></pre> <p>where "HandleError" is just a generic error handling method that would display details about the error.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload