WCF 内事务范围的问题
在我的项目中,DAL是WCF服务.Net4.0。使用数据库oracle 11g。我在 WCF(服务器端)中使用事务范围。 如果任何一个 sp 失败,我必须在方法(操作合约)内调用多个存储过程,我需要回滚已经执行的 sp。但回滚并没有发生。我没有使用客户端交易流程。
我已经放置了示例代码
公共类服务:IService {
public bool Method1()
{
using (TransactionScope Scope1 = new TransactionScope())
{
Method2();
Method3();
Scope1.Complete();
}
return true;
}
public bool Method2()
{
using (TransactionScope Scope2 = new TransactionScope())
{
// Procedure call .....
Scope2.Complete();
}
return true;
}
public bool Method3()
{
using (TransactionScope Scope3 = new TransactionScope())
{
// Procedure call .....
Scope3.Complete();
}
return true;
}
}
In my Project, DAL Is WCF service .Net4.0. using database oracle 11g. I am using transaction scope in WCF(server side).
I have to call more than one Stored procedure inside the method(operation contract) if any one sp failed, I need to rollback already executed sp. But rollback not happened. I am not used client side transaction flow.
I have placed sample code
public class Service : IService
{
public bool Method1()
{
using (TransactionScope Scope1 = new TransactionScope())
{
Method2();
Method3();
Scope1.Complete();
}
return true;
}
public bool Method2()
{
using (TransactionScope Scope2 = new TransactionScope())
{
// Procedure call .....
Scope2.Complete();
}
return true;
}
public bool Method3()
{
using (TransactionScope Scope3 = new TransactionScope())
{
// Procedure call .....
Scope3.Complete();
}
return true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看不出有任何理由不能按预期工作,就像你在那里放置代码的方式一样。
但是,如果您使用 WCF,您可能需要考虑使用 WCF 内置的事务流内容。您可以通过这种方式将整个 WCF 调用包装到单个事务中,而无需手动创建和管理 TransactionScope。 WCF 事务流程可以设置为需要在服务端进行事务,因此如果客户端没有通过,WCF 将为您启动一个事务。这样您就根本不需要编辑您的客户端。
http://msdn.microsoft.com/en-us/library/ms751413.aspx
I don't see any reason why that wouldn't work as expected, the way you have your code laid out there.
However if you are using WCF, you might want to consider using the transaction flow stuff built in to WCF. You can wrap the entire WCF call into a single transaction that way, without manually creating and managing TransactionScopes. The WCF transaction flow can be set up to require a transaction at the service side, so WCF will start a transaction for you if the client doesn't pass one. This way you wouldn't have to edit your client at all.
http://msdn.microsoft.com/en-us/library/ms751413.aspx