What is the best way to return multiple FaultExceptions from a WCF call?

advertisements

As the question says I am banging my head over the best way to return multiple FaultExceptions from one WCF call:

The scenario is the following:
ClientA makes a call to ClientB
ClientB makes many calls to ServerC some of which may return FaultExceptions

I would like to return all the FaultExceptions back to ClientA and I have not come across any good way to do it.

I have tried serializing and de-serializing both FaultExceptions and the MessageFault Objects with XmlSerializer, DataContractSerializer and NetDataContractSerializer to no avail.

The only elements I really care about are Reason, Code, and Detail. My last resort is to manually write code to serialize the Reason and the Code, but I am hoping to avoid that.

Are there any other ways to this this I am missing ?

Edit: Judging by the responses I have gotten I think my question was not very clear

In pseudo code I am trying to do the following:

class ClientA()
{
    Main()
    {
        ClientB.OperateOnManyValues(array[] values)
    }
} 

ClientB()
{
     OperateOnManyValues(array[] values)
     {
         foreach(Val val in values)
         {
             try
             {
                  ServerC.OperateOnOneValue(val)
             }
             catch(FaultException ex)
             {
                 errorList.Add(ex)
             }
         }
     return errorList
     }
}

Edit 2:

First of all I want to thank everyone for attempting to answer the question. I feel some of the answers are answers to different problems.
One poster suggested I throw an exception as soon as I get an error. Unfortunately that is now how the system is intended to work. Each value operated on is completely independent of the others and unaffected by the success or error of other values. I do not want one error to affect the processing of other values.
Another poster suggested returning some sort of data structure with all the FaultException data for all faults. That is what I would like to do, but the problem is that returning a list of FaultExceptions throws serialization errors. Is there any way to serialize a FaultException so I can return multiple in a list from a WCF call ?


Well... I don't fully understand the second part of the scenario. If your client B acts like the following

ServerC.A();
[...]
ServerC.B();
[...]
ServerC.C();

or

while(condition)
    ServerC.Call();

then the first exception is automatically rethrown to client B and possibly rethrown to A, so you don't have multiple exceptions to handle.

But if ClientB calls several methods of ServerC from different threads then you may have something like that. Still, if ClientB calls services from ServerC like this

try
{
    ServerC.A();
} catch(Exception ex)
{
    //store exception for A
}
    [...]
try{
    ServerC.B();
} catch(Exception ex)
{
    //store exception for B
}
    [...]
try
{
    ServerC.C();
} catch(Exception ex)
{
    //store exception for C
}

you have to deal it your own way.

In order to have a consistent exception

that reports information about the root cause, you have to use the InnerException property of the FaultException class, but you can't hold an array of InnerExceptions.

If yours is the case in which you do collect multiple exceptions and want to report them all

then you may create a custom FaultException class, inheriting from the former, with a property Exception[] InnerExceptions.

But, again, I don't really believe you have this kind of "multiple exceptions". Perhaps you meant nested exceptions, which are properly handled by InnerException regular property.

If you could show us some pseudo-code it would be of help.