background image

</configuration>

 

三:通过服务(操作)行为控制事务

通过服务契约确定事务流转的策略,通过事务绑定实施事务的流转;通过服务操作设置提
交方式及是否自动登记到事务之中

服务操作

OperationBehaviorAttribute 两个事务管理相关的属性:TransactionAutoComplete 和

 

TransactionScopeRequired

1:TransactionAutoComplete(默认值 Flase) 表示相应操作的执行是否自动纳入一个事务中;

2:TransactionScopeRequired(默认值 true) 表示如果执行过程没有抛出异常,完成后将自
动提交事务

;

    public class BankingService : IBankingService
    {       
        [OperationBehavior(TransactionScopeRequired = true)]
        public void Transfer(string fromAccountId, string toAccountId, double amount)
        {
        }
    }

 

四:事务相关的服务行为

ServiceBehaviorAttribute 定义的 4 个与事务相关的属性;

1:TransactionIsolationLevel:事务的隔离级别,默认值为 IsolationLevel.Seriallizable;

2:TransactionTimeout 以字符串形式定义事务的超时时限;

3:TransactionAutoCompleteOnSessionClose 在会话正常结束(没有异常)之后是否自动提交
或完成开启的事务,默认值

False

4:ReleaseServiceInstanceOnTransactionComplete 当事务完成之后是否要将服务实例释放掉,
默认值

False

    [ServiceBehavior(TransactionIsolationLevel=IsolationLevel.ReadCommitted,TransactionTimeo