WCF

Arogl Darthu's Blog

  • Homepage

Mar 27: Wcf Exception Shielding - Unexpected FaultContracts

So you've got Wcf Exception Shielding in place. All is well and the Enterprise Library Exception Handling Application Block takes care of those nasty exception details that you don't want your site visitors to know about... But have you ever had the urge to do more than just property mapping between exceptions and FaultContract? I know I have ;-)

There is a way to do this and it is actually quite simple to realize. You just have to create your own custom IExceptionHandler. But let's start with a bit of configuration. By default you would have an Exception Policy named "WCF Exception Shielding". Like so:

 <exceptionHandling>
   <exceptionPolicies>
     <add name="WCF Exception Shielding" />
   </exceptionPolicies>
 </exceptionHandling>
 

This policy handles specific Exception types and for each of those it will pass the exception through a chain of IExceptionHandlers. The last of these would normally be Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler. For instance:

 <exceptionTypes>
  <add type="System.DivideByZeroException, mscorlib"
      postHandlingAction="ThrowNewException" name="DivideByZeroException">
   <exceptionHandlers>
    <add exceptionMessage="Dividing by zero is not allowed."
       faultContractType="DivideByZeroFault, MyDll"
       type="FaultContractExceptionHandler, ExceptionHandling.WCF"
       name="Fault Contract Exception Handler">
     <mappings>
      <add source="Guid" name="Id" />
      <add source="Message" name="Message" />
     </mappings>
    </add>
   </exceptionHandlers>
  </add>
 </exceptionTypes>
 

Now what if your FaultContract would need additional data, that you can't just map from the Exception properties? For example:
- you might need the Message property of the InnerException;
- you need data that was logged to a database when the original exception got thrown.

To make this possible, just create your own IExceptionHandler that will be used instead of the provided FaultContractExceptionHandler. There are two things to keep in mind when you do this. First of all you should always set the postHandlingAction to ThrowNewException. Second, you should let your IExceptionHandler return a specific Exception type: FaultContractWrapperException. Read More
Posted by Twan Jacobs in WCF Comments: (0) Trackbacks: (0)

Jan 27: Proxy's Dispose results in Exception

A while ago I grabbed a WCF Membership example from here. Now that I've been reading some more on WCF, I stumbled upon the following article: http://msdn.microsoft.com/en-us/library/aa355056.aspx

How do you see this? Have you ever had these 'errors from IDisposable' surface in production? Did you start rewriting every client call with try-catch-finally? Personally I'm a bit appalled by the idea... Using the using statement keeps the code clean.

So I started searching for a solution. This article (WCF Gotcha #1) seems to provide a nice solution, but it's not exactly what I was hoping for.

Ideas are very welcome! Read More
Posted by Twan Jacobs in WCF Comments: (0) Trackbacks: (0)
« previous page   (Page 1 of 1, totaling 2 entries)   next page »

Calendar

Back February '12
Mo Tu We Th Fr Sa Su
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        

Archives

  • February 2012
  • January 2012
  • December 2011
  • Recent...
  • Older...

Categories

  • XML BizTalk
  • XML Daily Didst
  • XML Infra
  • XML SQL
  • XML WCF
  • XML WTF


All categories

Syndicate This Blog

  • XML RSS 2.0 feed
  • XML RSS 2.0 Comments

Blog Administration

Open login screen

Powered by

Serendipity PHP Weblog
 

Layout by Andreas Viklund | Serendipity template by Carl