事务范围 wcf 并避免不必要的升级为分布式事务
我在 WCF 应用程序中升级分布式事务时遇到问题。
我的代码看起来像这样:
LogRepository
public void AddLog(ImportLogDbo log)
{
using (DbManager dbManager = new DbManager("controlServerConnectionString"))
{
dbManager.SetSpCommand("dbo.ImportLog_Create",
dbManager.Parameter("@ImportFile", log.ImportFile),
dbManager.Parameter("@ImportError", log.ImportError),
dbManager.Parameter("@ImportHash", log.ImportHash),
dbManager.Parameter("@ImportCompleted", log.ImportCompleted))
.ExecuteNonQuery();
}
}
LogService
public void AddImportLog(string ImportFile, string ImportHash)
{
ImportLogDbo importLogDbo = new ImportLogDbo
{
ImportCompleted = false,
ImportFile = ImportFile,
ImportHash = ImportHash
};
if (_importLogRepository.GetByFileName(ImportFile) == null)
{
using (TransactionScope scope = new TransactionScope())
{
_importLogRepository.AddLog(importLogDbo);
scope.Complete();
}
}
}
项目位于 .NET 4 中,我使用 Sql Server 2008R2
上面的代码调用我的 wcf 服务,其配置如下
<wsHttpBinding>
<binding name="wsHttpBinding" transactionFlow="True" maxReceivedMessageSize="2147483647" closeTimeout="5:00:00" openTimeout="5:00:00" receiveTimeout="5:00:00" />
</wsHttpBinding>
<endpoint address="http://localhost:8080/AppServer/WsDocumentImportService" binding="wsHttpBinding" name="wsBinding" contract="ComDocs.AppServerServiceLibary.Abstract.IDocumentImportService"/>
我的问题是在事务范围内,它总是作为分布式提升。
我做错了什么吗? (我对 wcf 服务编程有点陌生)
谢谢
i have problem with escalation distributed transactions in wcf application.
My code looks something like this :
LogRepository
public void AddLog(ImportLogDbo log)
{
using (DbManager dbManager = new DbManager("controlServerConnectionString"))
{
dbManager.SetSpCommand("dbo.ImportLog_Create",
dbManager.Parameter("@ImportFile", log.ImportFile),
dbManager.Parameter("@ImportError", log.ImportError),
dbManager.Parameter("@ImportHash", log.ImportHash),
dbManager.Parameter("@ImportCompleted", log.ImportCompleted))
.ExecuteNonQuery();
}
}
LogService
public void AddImportLog(string ImportFile, string ImportHash)
{
ImportLogDbo importLogDbo = new ImportLogDbo
{
ImportCompleted = false,
ImportFile = ImportFile,
ImportHash = ImportHash
};
if (_importLogRepository.GetByFileName(ImportFile) == null)
{
using (TransactionScope scope = new TransactionScope())
{
_importLogRepository.AddLog(importLogDbo);
scope.Complete();
}
}
}
Project is in .NET 4 and i use Sql Server 2008R2
Code above call my wcf service, which is configured like this
<wsHttpBinding>
<binding name="wsHttpBinding" transactionFlow="True" maxReceivedMessageSize="2147483647" closeTimeout="5:00:00" openTimeout="5:00:00" receiveTimeout="5:00:00" />
</wsHttpBinding>
<endpoint address="http://localhost:8080/AppServer/WsDocumentImportService" binding="wsHttpBinding" name="wsBinding" contract="ComDocs.AppServerServiceLibary.Abstract.IDocumentImportService"/>
My problem is in transaction scope, which is ALWAYS promote as distribued.
I'm doing something wrong? (I am bit new in wcf service programming)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
transactionFlow = “true” 会将事务传播到服务边界之外。尝试将其设置为 false。您需要更细粒度的事务范围,可以使用该属性进行设置。有关详细信息,请查看以下内容:
http://msdn.microsoft.com /en-us/magazine/cc163432.aspx
transactionFlow = “true” will propagate the transaction outside the service boundary. Try to set it to false. You you need a more granular transaction scope you could set it using the attribute. for more info have a look at the below:
http://msdn.microsoft.com/en-us/magazine/cc163432.aspx