Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return Faults in JSON from AJAX Enabled WCF Service?
    primarykey
    data
    text
    <p>I have an <strong>AJAX-enabled WCF service</strong> (with enableWebScript in the behavior) that has a ValidationFault which I created.</p> <p>Here's the service:</p> <pre><code>[ServiceContract] public interface ICoreWCF { /// &lt;summary&gt; /// Saves the Customer. /// &lt;/summary&gt; [OperationContract] [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)] [FaultContract(typeof(ValidationFault))] void Customer_Save(Customer customer); } </code></pre> <p>Here's the fault:</p> <pre><code>[DataContract] public class ValidationFault { [DataMember(Name = "success")] public bool Success { get; set; } [DataMember(Name = "msg")] public string ValidationMessage { get; set; } [DataMember(Name = "errors")] public Dictionary&lt;string, string&gt; Errors { get; set; } } </code></pre> <p>I would like to send this fault back to the client javascript. The problem is that my custom fault's DataMembers are ignored and a general exception is returned.</p> <p><strong>How can I send the errors collection to the client?</strong></p> <p>I already tried writing my own <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ierrorhandler.aspx" rel="nofollow">IErrorHandler</a> similar to <a href="http://timclem.wordpress.com/2009/10/07/exception-shielding-for-json-wcf-services/" rel="nofollow">this</a>, such that it uses Exception Handling Application Block to convert an exception to a fault, and then the IErrorHandler serializes the resulting fault. But it appears that the JsonErrorHandler of the WebScriptingEnablingBehavior is not dealing well with the resulting Message object.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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