.Net - TransactionScope & Rollback

Why does the object implementing IEnlistmentNotification and forcing rollback in Prepare callback doesn't get notify to Rollback ? (my question may seem confusing, so here's a exemple)

Exemple
Suppose class A implements IEnlistmentNotification and if "Value" is odd, then it forces rollback in the Prepare callback.

A a1 = null;
A a2 = null;

using (TransactionScope tx = new TransactionScope())
{
  a1 = new A();
  a2 = new A();
  a1.SetValue(2);
  a1.SetValue(3);
  txt.Complete();
}

If we run the program, the result will be :

a1 will call Prepared(); // because 2 is even
a2 will call ForceRollback(); // because 3 is odd
a1 will call Rollback(); // because it gets notified to do so
the transaction fails with a ThreadAbordException
a1 has rollback
a2 hasn't rollback // lost of integretiy !!!!

Why doesn't a2 get notified to Rollback ? If a2 forced rollback, for sure it means he wants to get notified ! It's asking to rollback !

The problem is that in this situation, a1 has rollback but not a2, so there is a lost of integrity.

Can someone help me please figure out how it's suppose to work !?

Thanks,
Claude
jettaa2vr6Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b_levittCommented:
See "Nuance #2"
http://blog.jordanterrell.com/post/IEnlistmentNotification-Implementation-Nuances.aspx

"If you call ForceRollback() within your implementation of the Prepare() method, the Rollback() method will not be called on your resource.  "

Justification for this easily could have been that if an objects demands a rollback, than it already is aware of the rollback.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
b_levittCommented:
You know, I can assume that your example is a very simplified version of what you are actually trying to do, but I thought I should ask - is there a reason you don't simply handle this with nested transactions?  If class A represents a business object, I'm wondering why it also needs to be a resource manager.  It would be like SqlConnection having an "AddEmployee" method.  Just a thought,
0
jettaa2vr6Author Commented:
It's true, b_levitt, my example was a very simplified version of what I would like to do. To tell the truth, I am looking forward to implement SOA in our business : If SOA lies on WebServices, I was woundering how to handle transaction over multiple WebServices and for that reason I was looking at 2PC pattern. My research brought me to System.Transactions to encapsulate 2PC and I found stuff about IEnlistmentNotification and wanted to give it a try. So I created that simple A class to see how it would react. I totally agree that a business object shouldn't be a RM and for sure, a SqlConnection shouldn't be have a "AddEmployee" method ! I want to implement SOA, but I need to find a way, before I present the project to business managers, to make sure transactions will still work thru the system (even though it's WebServices's oriented).

By the way, thanks for the first info about the "ForceRollback". It was useful : now I understand why.
0
jettaa2vr6Author Commented:
Thank you for the excellent service and the speed at which the response was provided.
0
b_levittCommented:
Transaction management from a service standpoint is really more about statefull sessions than it is the actual transaction.

In your case I would consider WCF which does support transactions (i beleive as an implementation of the ws-transaction standard):

http://msdn.microsoft.com/en-us/library/ms752261.aspx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.