So, I went hunting, though I decompiled the RIA service code. It doesn't seem like you can significantly change the error information that is sent to the client.
You can override the OnError() method in DomainService, but this does not allow you to pass arbitrary information back, even if it is a custom exception type.
The reason is hidden inside the exception handling of the DomainServices.Hosting.QueryProcessor class.
If an unhandled exception occurs in a domain operation, it returns to its original state, and then FaultException () (which WCF processes) is ultimately thrown.
Unfortunately, the DomainServiceFault class DomainServiceFault very light ... It has only a few properties ...
public class DomainServiceFault { public int ErrorCode { get; set; } public string ErrorMessage { get; set; } public bool IsDomainException { get; set; } public string StackTrace { get; set; } public IEnumerable<ValidationResultInfo> OperationErrors { get; set; } public IEnumerable<ValidationResult> GetValidationErrors() {} }
and they are populated in ServiceUtility.CreateFaultExceotion() as follows:
DomainServiceFault detail = new DomainServiceFault(); <snip/> detail.ErrorCode = domainException.ErrorCode; detail.ErrorMessage = ServiceUtility.FormatExceptionMessage((Exception) domainException); detail.IsDomainException = true; if (current != null && !current.IsCustomErrorEnabled) detail.StackTrace = domainException.StackTrace; return new FaultException<DomainServiceFault>(detail, new FaultReason(new FaultReasonText(detail.ErrorMessage ?? string.Empty, CultureInfo.CurrentCulture)));
It is worth noting that in case of an exception, and not a validation error, OperationErrors not populated.
Thus, all this is due to the fact that I do not consider it possible to transfer or attach my own information about exceptions to the DomainService error handler (which is very unsuccessful).
Alastair pitts
source share