mysql分布式事务wcf_WCF 分布式事务 不会RollBack

要使用分布式事务 写了个例子  配置MSDTC  但事务不会回滚啊

using System.ServiceModel;

namespace School.Wcf.Contract

{

[ServiceContract]

public interface IStudentService

{

[OperationContract]

[TransactionFlow(TransactionFlowOption.Allowed)]

void Add(Student entity);

}

using System.ServiceModel;

using System.Transactions;

using School.Entity;

using School.DAL;

using School.Wcf.Contract;

namespace School.Wcf.Service

{

public class StudentService:IStudentService

{

[OperationBehavior(TransactionScopeRequired=true)]

void IStudentService.Add(Student entity)

{

Transaction tran = Transaction.Current;

DalCreater.CreateStudentDal().Add(entity);

}

}

namespace ClientForCAHost

{

public class StudentMng

{

StudentServiceClient client;

public StudentMng()

{

client = new StudentServiceClient();

~StudentMng()

{

client.Close();

}

public void Add(Student entity)

{

client.Add(entity);

}

}

protected void btnException_Click(object sender, EventArgs e)

{

Student s1 = new Student();

s1.Name = txtName1.Text.Trim();

s1.Remark = "有异常添加";

Student s2 = new Student();

s2.Name = txtName2.Text.Trim();

s2.Remark = "有异常添加";

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))

{

try

{

Transaction tran = Transaction.Current;

(new StudentMng()).Add(s1);

//throw new Exception("异常啦");

(new StudentMng()).Add(s2);

scope.Complete();

}

catch (Exception)

{

Transaction.Current.Rollback();

//throw;

}

}

Bind();

}

openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

transactionFlow="true" transferMode="Buffered" transactionProtocol="OleTransactions"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值