none
Manually set ambient transaction in WCF client RRS feed

  • Question

  • Hello,

    for a Service it is easy to accept Transactions:

    [TransactionFlow(TransactionFlowOption.Allowed)]

    For a service method to run in that transaction I would have to set:

    [OperationBehavior(TransactionScopeRequired = true)]

    If there is no Transaction, a new Transaction is created. But that Transaction is Serializable, by Default. I could override this behavior by specifying a ServiceBehavior:

    [ServiceBehavior(IsolationLevel=System.Transactions.IsolationLevel.ReadCommitted)]

    But then, if there is a Transaction from the Client, this Transaction must have this exact same Isolation Level.

    What I would like to do is:

    - Use the Transaction from the Client, whatever Isolation Level it has

    - If there is no transaction from the client: Create a new transaction but with Isolation Level "Read Committed"

    Is that possible?


    Monday, March 23, 2015 11:57 AM

Answers

  • It is not possible.

    When you are using WCF, you might want to consider using the transaction flow stuff built in to WCF. You can wrap the entire WCF call into a single transaction that way, without manually creating and managing TransactionScopes. The WCF transaction flow can be set up to require a transaction at the service side, so WCF will start a transaction for you if the client doesn't pass one. This way you wouldn't have to edit your client at all. http://msdn.microsoft.com/en-us/library/ms751413.aspx
    Understanding Transactions in WCF(https://praveenkatiyar.wordpress.com/2013/11/12/understanding-transactions-in-wcf/).

    Tuesday, March 24, 2015 6:04 AM