我有一个 C# Web 服务,我使用 jQuery Ajax 调用。它正常工作,除非在 web 方法中抛出自定义异常。由于某些原因,XmlHttpResponse 对象的 responseText 只具有基础 Exception 类的属性。因此,最终得到的 JSON 对象只包含以下属性:"ExceptionType"、"Message" 和 "StackTrace"。
我的自定义异常有一个名为 "FieldErrors" 的属性,在返回结果中没有显示。以下是该类的代码:
我的自定义异常有一个名为 "FieldErrors" 的属性,在返回结果中没有显示。以下是该类的代码:
[Serializable]
[XmlRootAttribute(Namespace = "http://www.mydomain.com/", IsNullable = false)]
public class ValidationException : Exception
{
public List<string> FieldErrors { get; set; }
public ValidationException(string message = null, Exception innerException = null) : base(message: message, innerException: innerException)
{
this.FieldErrors = new List<string>();
}
}
我的目标是让“FieldErrors”属性显示在JSON响应中。
SoapException
会有帮助吗? - John Saunders