views:

380

answers:

1

I'm calling a WCF service from a Silverlight client, therefore making all the calls async.

When the WCF service returns an ExceptionFault, the error object gets populated in the arguments to the Completed event handler...

proxy.UpdateCompleted += (o, e) =>
 {
     if(e.Error != null)
            .... do something
 }

what is the best approach for converting e.Error into a FaultException?

if (e.Error is FaultException<InvalidOperationFault>)
{
  var fault = e.Error as FaultException<InvalidOperationFault>;    
  ... do something
}

or

try
{
   throw e.Error
}
catch(FaultException<InvalidOperationFault> fault)
{
   ... do something
}

or can you suggest anything better?

A: 

This just boils down to the lack of Switch on type support in C#

http://stackoverflow.com/questions/298976/c-is-there-a-better-alternative-than-this-to-switch-on-type

Andronicus