Transactions with ASP.net API

I understand that the ASP.NET WEB API was created to help implement lightweight REST-based applications. However, I need my REST services to be transactional / part of the transaction. I tried to look back, but it seems that there is no way to enlist the WEB API as part of a client-initiated transaction. Is there any way to do this?

Regards Jagadish

+6
source share
3 answers

I believe that you mean distributed transactions (through MSDTC) that can spread across service boundaries.

However, distributed transactions through WCF RESTful services are not possible because it is simply not possible to distribute and manage the state of a transaction over simple HTTP requests.

You might want to look at simple WCF services through HTTP (wsHttpBinding) or TCP / IP (net.tcp), or even look at WCF Data Transfer Services .

+4
source

If you control both ends of the wire, you can achieve what you want.

There is a TransactionInterop class to provide support for working with transactions between process boundaries using MS DTC.

It contains two methods that are interesting to your scenario:

You can use the first method in your client to create a transaction. You can set it as a custom header value or cookie to transfer it to the service. After using the service, you can use the second method to create the transaction locally.

The main caveat is that MS DTC will need to be activated and configured on the client and server. This is really achievable if your services are invoked in a Windows Active Directory domain.

+11
source

Including service calls in a transaction is usually considered a SOAP behavior, not a REST behavior. At least there is a standardized way to do this using SOAP called WS-AtomicTransaction.

Being SOAP oriented, this is clearly not supported by ASP.Net Web API, but is supported by WCF

http://msdn.microsoft.com/en-us/library/ms730266

It would be possible to implement similar similar behavior in REST, but it is relatively difficult to do reliably.

+4
source

Source: https://habr.com/ru/post/919520/


All Articles