开发者

WCF transactions

I imagine the following WCF service usage: (of a cash acceptor)

Service Consumer 1                           Service Consumer 2
cashAcceptorService.BeginTransaction();     cashAcceptorService.StopDevice();
                                            //this should throw exception: device is locked / used in a transaction                                     
cashAcceptorService.AcceptMoney();          

cashAcceptorService.EndTransaction();

Service Consumer 1 and 2 use the same WCF single instance. I wonder if this functionality is already implemented. Do WCF trans开发者_开发知识库actions offer this?

How do you see this done?


If the following is true:

  • The service is interacting with a transactional object (eg the database)
  • The service has transaction flow enabled

Then WCF does indeed offer this.

The client can then use the TransactionScope class. Any transactions initiated on the client will flow through to the service automatically.

using(TransactionScope transactionScope = new TransactionScope())
{
     // Do stuff with the service here
     cashAcceptorService.AcceptMoney();
     //
     //
     transactionScope.Complete();
}

Handling transactions in WCF tends to be an entire chapter of a book, but this should be enough information to get you on the right track.


It is always better to understand the concept of distributed transactions . I recommend to read this article http://www.codeproject.com/Articles/35087/Truly-Understanding-NET-Transactions-and-WCF-Imple

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜