0

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

Mennion
  • 2,873
  • 3
  • 20
  • 34

1 Answers1

0

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

Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70
  • Well, if i understand, transactionFlow = "true" is good for transaction initialized in client? Btw transactionFlow set in false not work, still same problem. – Mennion Aug 24 '11 at 14:25
  • in general Each Participating Component Should Manage its Own Transactions(if there is not a specific business rule about that) .anyway in this case you don't need to propagate the transaction as the Repository.AddLog doesn't use any. In your case would be better wrap the repository into a transaction scope and handle the exception at service level – Massimiliano Peluso Aug 24 '11 at 14:30
  • Yes, this is a bit wrong example. But elsewhere in appliacation i have service with method which calls two-theree repository in one transaction... – Mennion Aug 24 '11 at 14:34
  • the repository should manage the transaction then and it should be treated as a UnitOfWork.Don't use any transaction at WCF level in this case – Massimiliano Peluso Aug 24 '11 at 14:42