nvoigt
nvoigt

Reputation: 77304

WCF Distributed Transaction Flow using normal return values

I have got a service that should use distributed transactions.

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public bool ServiceMethod(int parameterPlaceHolder)
{
  return SomeOperationResult();
}

For reasons out of my responsibility, this service should never throw faults. On success it returns one value, on failure another (abstracted to a bool here for demo purposes).

The transaction flowing works.

However, the attribute implies that any result that is not an uncaught exception will complete the transaction. That's not the behavior I want. I want to control the outcome of the transaction myself. On returning false, I want to have the transaction fail.

I have tried various methods:

I'm out of ideas. Does anyone know how to create my own transaction scope, using a flowed distributed transaction, not using the Microsoft AutoComplete-On-Normal-Return pattern? I would like to not complete the transaction without throwing an exception.

Upvotes: 1

Views: 452

Answers (1)

usr
usr

Reputation: 171188

Transaction scopes can nest. The entire transaction aborts if you don't completed any scope. So:

using (new TransactionScope()); //Doom transaction

Better comment this line.

You can also try to call stuff on Transaction.Current but I have no experience with that.

Upvotes: 1

Related Questions