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?
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With