I am showing a WCF service through basicHttpBinding
, which performs several database operations.
I want to guarantee that if the client does not receive a response, the database operations will be rolled back (without a transaction flow through WCF). For instance. the client calls the DoX method, which runs on the server, but the client crashes before it finishes. Then database operations should be discarded as soon as the response is not sent to the client.
Is there any way to do this? Will the [OperationBehavior(TransactionScopeRequired=true)]
attribute work this way? Is it possible to handle communication errors on the server side?
Update 1: It seems that [OperationBehavior(TransactionScopeRequired=true)]
completes the transaction before sending a response to the client and therefore cannot be used to roll back if the client does not receive the response.
Update 2: To make this clear, I donโt need the transaction to interact with the client in any way. The client should not know about the transaction, be able to cancel or commit it, and also should not go through the transaction through the binding. The only place I want the rollback transaction to be done on the server side is if the transport channel cannot deliver the message to the receiving client. In the case of TCP / IP, this information should be easily accessible to the server. (No TCP packet ACK send back to client)
So, a hypothetical server-side execution thread (note the lack of a client side):
Receive client request Start transaction Execute all logic inside the service operation Send reply back to client if (reply.failedToReceive) { transaction.Rollback() } // due to a failing TCP/IP transmission
source share