.net - Can I prevent WCF from rolling back the transaction when a fault is thrown? -
consider following wcf service participates in distributed transaction. normal behavior of wcf roll transaction if fault occurs. there way override behavior?
service contract:
[servicecontract] public interface itestservice { [operationcontract] [faultcontract(typeof(testservicefault))] void throwerror(); [operationcontract] void dosomething(); [operationcontract] void dosomethingelse(); } [datacontract] public class testservicefault{}
service implementation:
class testservice : itestservice { [operationbehavior(transactionscoperequired = true)] [transactionflow(transactionflowoption.mandatory)] public void throwerror() { throw new faultexception<testservicefault>(new testservicefault()); } [operationbehavior(transactionscoperequired = true)] [transactionflow(transactionflowoption.mandatory)] public void dosomething() { // // ... // } [operationbehavior(transactionscoperequired = true)] [transactionflow(transactionflowoption.mandatory)] public void dosomethingelse() { // // ... // } }
client implementation snippet:
using(new transactionscope()) { testserviceclient.dosomething(); try { testserviceclient.throwerror(); } catch(faultexception<testservicefault>) {} testserviceclient.dosomethingelse(); }
when faultexception thrown throwerror(), wcf rolls distributed transaction includes work done dosomething(). then, client call dosomethingelse() fails message the flowed transaction not unmarshaled. following exception occurred: transaction has been implicitly or explicitly committed or aborted.
in particular scenario behavior undesirable. i'd catch exception on client side , continue business. if exceptions occur don't catch, client roll transaction.
note: question duplicate of how handle faultexception in wcf without aborting whole transaction?, accepted answer there isn't satisfactory me - it's important of operations happen within same transaction scope.
well, try setting transactionautocomplete=false on service side, , use settransactioncomplete() prevent exception rolling work back.
Comments
Post a Comment