Client FaultException policy for ExceptionHandling block

Topics: Exception Handling Application Block
Sep 16, 2008 at 6:14 PM
Edited Sep 16, 2008 at 8:07 PM
I'm looking to use the Exception Handling block from a WCF client.  The scenario I have is that the service could throw a 'typed' FaultException that I'd like to have handled via policy on the client.  e.g. FaultException<CustomerNotFoundFault>

The client is also a broker, of sorts, so its impractical to catch(FaultException<CustomerNotFoundFault>) for each of the permutations, but it is possible to handle via categorizing through policy - I think anyway.

I'd like to basically register an exception type (actually, several) like so:

<exceptionPolicies>
    <
add name="Retry Message">
        <
exceptionTypes>
            <
add type="System.ServiceModel.FaultException`1[ExceptionGenerator.CustomerNotFoundFault], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None" name="ExceptionGenerator.CustomerNotFoundFault"/>
        
</exceptionTypes>
    </
add>
</
exceptionPolicies>

This obviously doesn't work, but are their any ideas on how to accomplish this?  The Fault Contract Handler seems specifically geared towards a server side implementation, though a custom IExceptionHandler looks like it might work. 

I thought I'd ask and see if there was a standard way for handling these 'typed' faults through policy? :)

Thanks,
Zach




 

 

 

Sep 17, 2008 at 4:34 PM

Hi Zach,

Registering fault exceptions should indeed work; here's a sample of what it would look like:

            <add name="policy">

                <exceptionTypes>

                    <add type="System.ServiceModel.FaultException`1[[HandlingFaultExceptions.Fault1, HandlingFaultExceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

                        postHandlingAction="NotifyRethrow" name="Exception">

                        <exceptionHandlers>

                            <add type="HandlingFaultExceptions.MyHandler, HandlingFaultExceptions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

                                name="Custom Handler" />

                        </exceptionHandlers>

                    </add>

                </exceptionTypes>

            </add><!--EndFragment-->

Would this help you?

Fernando

 

 

Sep 17, 2008 at 7:50 PM

Hi Fernando!

My stumbling block appears to have been how to define a fully qualified type name of for a generic type,  e.g. tyepof(FaultException<ConsultantNotFoundFault>), in the app.config using double '[[' .  I was using a single '[', which gave me the error 'type cannot be resolved.'.  Your sample shows this and I was able to successfully use the library as I expected.  A fragment of the updated confguration is below.


Thank you!
Zach
<exceptionPolicies>
           <add name="Retry Message">
               <exceptionTypes>
                   <add type="System.ServiceModel.FaultException`1[[ELEaxPolicy.ConsultantNotFoundFault, ELEaxPolicy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                        postHandlingAction="None" name="ConsultantNotFoundFault" />
               </exceptionTypes>
           </add>
       </exceptionPolicies>

 

 


 

Sep 17, 2008 at 10:11 PM
Zach,

It's great that it's working for you now. Unfortunately the type picker doesn't make this easy.

Fernando