Previous | Home | Next |
WCF services can work directly against a transactional resource and manage the transaction explicitly using programming models such as that offered by ADO.NET
[ServiceContract] interface IMyContract { [OperationContract] void operation( ); } class MyService : IMyContract { public void operation( ) { //Avoid this programming model: string str = "..."; IDbConnection connection = new SqlConnection(str); connection.Open( ); IDbCommand idbcomm = new SqlCommand( ); idbcomm.Connection = connection; IDbTransaction transaction = connection.BeginTransaction( );//Enlisting idbcomm.Transaction = transaction; try { /* Interact with database here, then commit the transaction */ transaction.Commit( ); } catch { transaction.Rollback( ); //Abort transaction } finally { connection.Close( ); idbcomm.Dispose( ); transaction.Dispose( ); } } }
WCF Resource Managers:
A WCF Resource Manager (RM) is any resource that supports both automatic enlistment and the two-phase commit protocol managed by one of WCF's transaction managers.
The resource must detect that it is being accessed by a transaction and automatically enlist in it exactly once. The RM can be either a durable resource or a volatile resource, such as a transactional integer, string, or collection.
Previous | Home | Next |