views:

467

answers:

3

I would like to configure WCF service operations to accept a transaction if my client sends one, but not to create one if none is sent. I think this would be similar to the Supported transaction attribute in COM+.

Does anyone know whether this can be accomplished with WCF transactions?

I am trying to accomplish this all by using the WCF transaction programming model (e.g. TransactionFlowAttribute and TransactionScopeRequired on service operations) rather than using the System.Transactions explicit transaction programming model.

Here's an example of why I think I want to be able to do this:

ServiceA implements a high-level business operation which invokes two data services. An operation in Service B does a single database update and an operation in Service C does two database updates.

ServiceA ----> ServiceB ----> <1 DB update>
|
V Service C ----> <2 DB updates>

ServiceC's 2 database updates need to be performed within a transaction with its root on ServiceC. Service B's single database update does NOT need to take place within a transaction. However, ServiceA defines a transaction that requires ServiceB and ServiceC's database updates two happen as an atomic unit of work.

My question is how I can configure ServiceB so that when it's invoked by ServiceA it enlists in that transaction. However, when ServiceB is invoked directly rather than through Service A it does not need to run within a transaction because it's only doing one database update.

Thanks,

David Madrian

+1  A: 
Tuzo
Thanks for your response, but I wanted to know if the service could not create a transaction if the client doesn't send one but enlist in a transaction sent by the client. I think the configuration settings you've described above are what Juval Lowy calls "Client\Server" transaction mode. He says that this mode "ensures the service uses the client transaction if possible, or a service-side transaction when the client does not have a transaction." What I'm looking for is the case where the server uses the client transaction if it's there, but if no client txn the server doesn't have a txn.
David Madrian
A: 

Thanks for the very helpful answer. I think your Option 2 gets at the real issue. My only concern with having a transaction in that scenario was performance. But, if performance is not an issue (since a lightweight transaction is used, which doesn't affect performance significantly), I'm fine with letting that transaction be created where it's not really needed.

David Madrian
David, just some FYI's: stackoverflow is not a discussion forum so comments should not be posted as answers -- that's what the add comment feature is for. Also, if an answer is helpful then it's recommended to vote it up. Similarly if an answer satisfactorily answers your question then you should accept the answer.
Tuzo
A: 

I posted the same question on MSDN and received some additional answers there that are interesting. Here's the link: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/7d3541b2-2c23-4a25-91a8-4a889c4d08be/

I'd be curious to hear what anyone thinks about the responses on MSDN.

David Madrian