views:

254

answers:

1

Is it possible to have a DataServiceException pass along a list of errors to consumers?

Rather than just receive the standard Message, Stacktrace information I would also like to have a list of errors when various validations fail on a model.

I tried to set the DataServiceException's inner exception to FaultException.

[DataContract]
public class MyTypeWithExtraInfo
{
   [DataMember]
   public List<MyErrorInfo> MyErrors { get; set; }
}

[DataContract]
public class MyErrorInfo
{
   [DataMember]
   string PropertyId { get; set; }

   [DataMember]
   public string Error { get; set; }
}

Clientside I do get the DataServiceException but the operation's message only has the FaultException Reason and Type (ToString'ed) it does not have the DataMembers that I have specified in MyTypeWithExtraInfo.

+1  A: 

For a single exception, you can catch the actual exception and rethrow:

throw new System.ServiceMode.FaultException("Custom Error Message");

However, if you need to handle multiple exceptions, consider using the Task Parallel Library Extensions for .NET. This will allow you to collect all of the thrown exceptions and place them into a single AggregateException object. This library is slated to become part of the .NET 4.0 framework.

Chris Ballance
I'm sorry I should have stated that I am trying to use a typed FaultException<T> where I have another object that contains additional information about the error. That object is marked as a DataContract and its DataMembers are not being serialized and sent to the client.I have tried what you stated and on the client side all I get is the FaultException Message and Type but not the extra information I would like to pass over.
Hooveh
What is the additional information you want to pass?
Chris Ballance
I'm looking to perform validation over an entire model during a save. I want to gather all of the validations that fail (not send back one at a time) and then pass all of the errors back together at once. Using something like an object with a list of a bunch of errors.
Hooveh
Please see my updated answer.
Chris Ballance
Hi Chris thanks for the info although this is not a multi processor/hardware issue. I updated the original question with some example code.
Hooveh

related questions