Search code examples
.netdatabaseweb-servicesdistributedmsdtc

Is it possible to have two applications that use the same databases in a distributed transaction without having to implement a resource manager?


We have a .Net application that initiates a transaction using NHibernate and modify data in the database X. Amid this transaction we issue calls to a WebService (.Net too), that also modifies database X and possibly modifies other databases.

Is there a way to share this transaction between the two applications without having to write a resource manager for the webservice? (it's the only way I see)

How can the application that initiates the transaction be aware of (and control) the database transactions that the WebService starts?


Solution

  • If you are using WCF, then it's rather simple. All you have to do is place the TransactionFlowAttribute on the methods on your contract which you want to have a transaction flow through it.

    Then, you would create a TransactionScope instance around the database call and the call to the web service on the client, and the transaction will be coordinated between your call to the database and the web service.

    IIRC, you need the Distributed Transaction Controller service running in order to coordate the transaction.

    If you are not using WCF, then yes, you'll have to create a resource manager. The best way is to probably have a resource manager specific to the two resources you are trying to manage in the specific transaction and use compensating transactions to commit/rollback depending on the state of the responses from the individual resources participating in the transaction.