6

I am exposing a WCF service through a basicHttpBinding that executes several operations on a database.

I want to guarantee that if the client does not receive the reply the database operations are rolled back (without any transaction flow through WCF). E.g. the client calls the "DoX" method which executes on the server but before it is finished the client crashes. The database operations should then be rolled back as soon as the reply can not be send to the client.

Is there any way to do that? Will the [OperationBehavior(TransactionScopeRequired=true)] attribute work in such a manner? Is there a possibility to handle communication errors on the server side?

Update 1: It seems [OperationBehavior(TransactionScopeRequired=true)] commits the transaction before the reply is send to the client and thus can not be used to perform a rollback if the client does not receive the reply.

Update 2: To state it clearly again, I do not have the need for the transaction to interact in any way with the client side. The client should neither know of the transaction, have the ability to cancel or commit it, nor should any transaction flow through the binding. The only place I want the transaction to rollback is on the server side if the transport channel can not deliver the message to the receiving client. With the case of TCP/IP this information should be readily available to the server. (No ACK of the TCP packet send back to the client)

So a hypothetical execution flow on the server side (notice the lack of client side) should be:

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
11
  • To do transactions in WCF you need WS-Transaction. This will not work with a basicHttpBinding endpoint. It Requires wsHttpBinding. For more details, see this question Feb 15, 2012 at 15:10
  • Why do you need to use basiHttpBinding? wsHttpBinding will give you this. Feb 15, 2012 at 15:12
  • 1
    I am not trying to pass a transaction through WCF to the client, the transaction should exclusively be on the server side and thus not use mechanisms like WS-Transactions.
    – GaussZ
    Feb 15, 2012 at 15:32
  • @JustinDearing: The clients accessing the service do not support wsHttpBinding.
    – GaussZ
    Feb 15, 2012 at 15:34
  • 1
    With basicHttpBinding, there's no way to know whether the client receives the response or not. Feb 21, 2012 at 19:58

1 Answer 1

1

There is no easy answer to this question. You are asking for a behaviour that is implemented in WS-* but done using basic SOAP. I think your only option if you REALLY can't switch to wsHttpBinding or use duplex as suggested by @Trevor Pilley is to try to mimic the behaviour of WS-Transaction in your own custom protocol based on basic SOAP.

You should be able to get some simplification over the full WS-Transaction specification because

  • You will probably only need to support transactions over a single service - you will not be doing a distributed transaction over several independent services
  • You will not need to support both short a transactions (WS-AtomicTransaction) as well as long running transactions (WS-BusinessActivity) probaby atomic transactions would do
  • You would not need to support any kind of extensibility model (WS-Coordination)
  • You would not need to implement a discovery/metadata model that describes the protocol (e.g. like WSDL) because you would be coding the protocol behaviour directly into the client and service.

However, you would probably need elements of both WS-Coordination and WS-AtomicTransaction. This is not a simple task by any means and it will be easy to miss something subtle that could cause either rollbacks to not happen or (just as bad) to destroy the performance of your service by having long duration locks all over your database due to crashed clients.

Like I say, this is a complex behaviour and if you cannot use ready-made, standardised protocols, there is no simple answer.

4
  • I added further clarification to the question. I only want to rollback the transaction if the transmission of the reply message from the client to the server fails. The client never comes into play, or only in so far that the client fails to receive the TCP/IP packets.
    – GaussZ
    Feb 21, 2012 at 20:42
  • 1
    But how is the service to know if the client has received the message? Wouldn't it have to notify the service in a second call for example, to a Commit method passing in a transaction ID that it got from the response to the initial service call... Feb 21, 2012 at 20:51
  • I see what you're thinking with the TCP/IP ACK but you are using HTTP and I don't think the underlying TCP/IP is exposed by WCF. and in fact, HTTP is not necessarily based on TCP/IP. Any reliable transport will do. This possibly implies that an implementation that strictly obeys the standard would not expose the underlying wire protocol. Feb 21, 2012 at 21:13
  • It might be the case that WCF actually hides that yes; I am digging a bit through the WCF code and haven't located yet in source where the reply message is actually send through the transport layer. But theoretically if a hook into that place is possible it could work.
    – GaussZ
    Feb 21, 2012 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.