Configuring Fault Contract Exception Handlers in Enterprise Library 6 for WCF -
how map additional properties of exception custom fault contract when using enterprise library 6's exception handling application block?
this article describes faultcontractpropertymapping same way this 1 does. if have fault contract so:
[datacontract] public class salarycalculationfault { [datamember] public guid faultid { get; set; } [datamember] public string faultmessage { get; set; } }
how add property , map original exception? lets want show stored procedure name client using new property:
[datamember] public string storedprocedurename { get; set; }
i try editing mapping shown on page 90 of "developer's guide microsoft enterprise library-preview.pdf" which can found here not seem work. new mapping looks this:
var mappings = new namevaluecollection(); mappings.add("faultid", "{guid}"); mappings.add("faultmessage", "{message}"); mappings.add("storedprocedurename", "{procedure}"); //sqlexception has procedure property
and here policy.
var testpolicy = new list<exceptionpolicyentry> { { new exceptionpolicyentry(typeof(sqlexception), posthandlingaction.thrownewexception, new iexceptionhandler[] { new faultcontractexceptionhandler(typeof(salarycalculationfault), mappings) }) } }; var policies = new list<exceptionpolicydefinition>(); policies.add(new exceptionpolicydefinition( "testpolicy", testpolicy)); exmanager = new exceptionmanager(policies); exceptionpolicy.reset(); exceptionpolicy.setexceptionmanager(exmanager);
when , catch faultexception on client , inspect it, storedprocedurename empty. why doesn't map sqlexception new property in fault exception?
it turns out shouldn't place code expect exception inside of exceptionmanager.processs() method. doing before:
exmanager.process(() => wimdal.execute_nonquerynoreturn(sc), "testpolicy");
insead, execute code normal.
wimdal.execute_nonquerynoreturn(sc);
this not follow "developer's guide microsoft enterprise library-preview.pdf" says guess documentation still work in progress. hope helps else.
Comments
Post a Comment