开发者

Transaction scope wcf and avoid unwanted Escalation to Distributed Transactions

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜