TransactionIsolationLevel and multiple service contracts
I have a service which implements several contracts, which works fine, e.g.
class MyService : IMyContract1, IMyContract2
{
// Implement both interfaces in here
}
This works fine, but in my case IMyContract2 has an operation where I want to flow a transaction, so I use an attribute to set this on the operation:
[OperationBehavior(TransactionAutoComplete=true, TransactionScopeRequired=true)]
I want to set the isolation level for this, so I add this attribute to the Service:
[ServiceBehavior(TransactionIsolationLevel=IsolationLevel.ReadCommitted)]
The problem is, when I try to host this service, I get the following exception:
Unhandled Exception: System.InvalidOperationException: The service 'MyService' is configured with a TransactionIsolationLevel but no operations are configured with TransactionScopeRequired set to true. TransactionIsolationLevel requires at least one operation with TransactionScopeRequired set to true.
I've played around with this and found that if I switch the order of the interface declarations, then it works, i.e.
[ServiceBehavior(TransactionIsolationLevel=IsolationLevel.ReadCommitted)]
class MyService : IMyContract2, IMyContract1
{
// Implement both interfaces in here
}
I guess this means that it is only checking the first interface for methods which have TransactionScopeRequired set true, which is a bug. I can use this to get around it in this case, but now I'm trying to inherit from a base class which implements the interface which requires that I do not flow transaactions (i.e. has no operations configured with TransactionScopeRequired set to true). As C# insists that the base class appears first in the list, I can't re-order them to fix the problem!
[ServiceBehavior(TransactionIsolationLevel=IsolationLevel.ReadCommitted)]
class MyService : MyServiceBase, IMyContract2, IMyContract1
{
// MyServiceBase implements IMyContract1
// Implement IMyContract2 interface in here
}
Does anyone have a workaround for this? And can anyone at Microsoft help and fix the bug for future releases, or explain this 'feature'?

