1

I have a simple update method like below:

public static void Execute()
{
    var conn = new SqlConnection(ConnectionString);
    conn.Open();
    var cmd = new SqlCommand(UpdateQuery, conn);
    cmd.ExecuteNonQuery();
}

Case 1

When I call this method from a Console Application everything works as expected. Since I do not Complete the TransactionScope update is rollbacked.

using (new TransactionScope())
{
    TestUpdate.Execute();
}

Case 2

I create a WCF service and call this method inside the wcf operation like below. Again everything works as expected. Since I do not Complete the TransactionScope update is rollbacked.

// Interface
[OperationContract, TransactionFlow(TransactionFlowOption.Allowed)]
void DoWork2();

// Implementation
public void DoWork2()
{
    using (new TransactionScope())
    {
        TestUpdate.Execute();
    }
}

// Console App
var client = new StaticServiceClient();
client.DoWork2();

Case 3

I start a transaction in the Console Application and call the service from the Console Application with in this transaction. When I debug I can see that Transaction.Current is not null on IIS and I expect code executed in IIS will use this transaction. But below exception is thrown inside conn.Open();.

The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)

// Interface
[OperationContract, TransactionFlow(TransactionFlowOption.Allowed)]
void DoWork();

// Implementation
[OperationBehavior(TransactionScopeRequired = true)]
public void DoWork()
{
    TestUpdate.Execute();
}

// Console App
using (new TransactionScope())
{
    var client = new StaticServiceClient();
    client.DoWork();
}

Question

Console Application is executed on my local machine and WCF service is hosted on my local IIS. Database is on another server in the same network. I believe, first two cases prove that MSDTC is working fine on both my local machine and the database server. Then, what may be the problem with the third case?

Configurations

Server

<bindings>
  <wsHttpBinding>
    <binding name="soapBinding" transactionFlow="true">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service name="ServiceLib.StaticService">
    <endpoint contract="ServiceLib.IStaticService" name="soap" binding="wsHttpBinding" bindingConfiguration="soapBinding" address="http://localhost:58759/StaticService.svc/Soap" />
  </service>
</services>

Client

<bindings>
  <wsHttpBinding>
    <binding name="soap" transactionFlow="true">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:58759/StaticService.svc/Soap"
    binding="wsHttpBinding" bindingConfiguration="soap" contract="ServiceReference.IStaticService"
    name="soap" />
</client>
Mehmet Ataş
  • 11,081
  • 6
  • 51
  • 78
  • Hmmm... are you sure case 1 and 2 are really using distributed transactions? I'd try subscribing to the [TransactionManager.DistributedTransactionStarted event](https://msdn.microsoft.com/en-us/library/system.transactions.transactionmanager.distributedtransactionstarted%28v=vs.110%29.aspx) to make sure. – nodots Jul 23 '15 at 11:41
  • Yes, I subscribed and event has not been fired. Even more, I stopped MSTDC service and Case 1 and 2 are still working! Then what are they using, who is managing my transactions :) I have "Use local coordinator" checked in Component Services > Computers > My Computer > Properties > MSDTC. – Mehmet Ataş Jul 23 '15 at 11:55
  • So at least you've narrowed it down to an MSDTC config problem, as the error indicated. Can't help you there since I'm not experienced in DTC really. As to "who is managing your transaction" however, transactions are only promoted to distributed transaction under certain circumstances; in many cases they can run as so-called lightweight transactions. [You may find some pointers here.](http://stackoverflow.com/questions/1690892/transactionscope-automatically-escalating-to-msdtc-on-some-machines) – nodots Jul 23 '15 at 12:02

1 Answers1

1

Make sure the DTC security settings are as below on both WCF and DB servers:

enter image description here

tom redfern
  • 30,562
  • 14
  • 91
  • 126