.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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -