事务范围 wcf 并避免不必要的升级为分布式事务

发布于 2024-12-01 08:01:15 字数 1926 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是在用心讲痛 2024-12-08 08:01:15

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文