我在 wcf 应用程序中遇到升级分布式事务的问题。
我的代码看起来像这样:
日志存储库
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();
}
}
日志服务
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 服务编程有点陌生)
谢谢