Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AggregateException and WCF

I'm calling a WCF service, which under certain conditions returns an AggregateException, with all the problems that happened through the call

On the other side, I'm getting a FaultException (which makes sense, because WCF understands only about these exceptions). The problem is, the Detail for the contract is not an aggregate exception. It's as if by default, WCF gets the 1st exception for the AggregateException list of exceptions (InnerExceptions), and encapsulates that. So on the client side, i'm just getting the first exception of the list. After investigating a bit, i did the following :

Added this to the contract

[FaultContract(typeof(AggregateException))]

Then on the service call..

try
{
    BaseService.Blabla.Delete(item);
}
catch (AggregateException ex)
{
    throw new FaultException<AggregateException>(ex);
}  

But on the other side, which is this :

catch (FaultException<AggregateException> ex)
{
    string msg = string.Empty;
    foreach (var innerException in ex.Detail.InnerExceptions)
    {
        msg += innerException + Environment.NewLine;
    }
    MessageBox.Show(msg);
}
catch (Exception ex)
{
    throw ex;
}

It's getting into the Exception catch statement instead, and getting an error like this (which is obviously some random error, because i don't have any connection issues, and debugging this returns immediately, 4 minutes never pass) :

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:03:59.9939994'. : An existing connection was forcibly closed by the remote host

What am i missing?

like image 547
Daniel Perez Avatar asked Jun 03 '11 12:06

Daniel Perez


People also ask

What is the difference between fault exception and regular dot net exception?

Exceptions are used to communicate errors locally within the service or the client implementation. Faults, on the other hand, are used to communicate errors across service boundaries, such as from the server to the client or vice versa.


1 Answers

The evil is, your fault detail derives from exception. Read Using custom FaultContract object containing System.Exception causes 'Add Service Reference' to fail – mho. For example

         [DataContract] 
         public class AggregateFault 
         {     
                 [DataMember]     
                 public string Message { get; set; } 
         }

then FaultException<AggregateFault > works perfect but not FaultException<AggregateException>

like image 194
Om Deshmane Avatar answered Oct 16 '22 17:10

Om Deshmane