【问题标题】:WCF The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)WCF 合作伙伴事务管理器已禁用其对远程/网络事务的支持。 (来自 HRESULT 的异常:0x8004D025)
【发布时间】:2015-07-23 11:12:58
【问题描述】:

我有一个简单的更新方法,如下所示:

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

案例一

当我从控制台应用程序调用此方法时,一切都按预期工作。由于我没有Complete,因此回滚了 TransactionScope 更新。

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

案例 2

我创建了一个 WCF 服务并在 wcf 操作中调用此方法,如下所示。一切都按预期工作。由于我没有Complete,因此回滚了 TransactionScope 更新。

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

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

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

案例 3

我在控制台应用程序中启动一个事务,并在此事务中从控制台应用程序调用服务。当我调试时,我可以看到 Transaction.Current 在 IIS 上不为空,我希望在 IIS 中执行的代码将使用此事务。但在conn.Open(); 内抛出了以下异常。

合作伙伴事务管理器已禁用对远程/网络事务的支持。 (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();
}

问题

控制台应用程序在我的本地计算机上执行,WCF 服务托管在我的本地 IIS 上。数据库位于同一网络中的另一台服务器上。我相信,前两个案例证明 MSDTC 在我的本地计算机和数据库服务器上都运行良好。那么,第三种情况可能有什么问题呢?

配置

服务器

<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>

客户

<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>

【问题讨论】:

  • 嗯...您确定案例 1 和 2 真的使用分布式事务吗?我会尝试订阅TransactionManager.DistributedTransactionStarted event 以确保。
  • 是的,我订阅了并且事件没有被触发。更重要的是,我停止了 MSTDC 服务,案例 1 和 2 仍在工作!那么他们在使用什么,谁在管理我的交易:) 我在组件服务 > 计算机 > 我的电脑 > 属性 > MSDTC 中选中了“使用本地协调器”。
  • 因此,至少您已将其范围缩小到 MSDTC 配置问题,如错误所示。因为我在 DTC 方面没有经验,所以无法帮助你。然而,关于“谁在管理你的事务”,事务仅在某些情况下才被提升为分布式事务;在许多情况下,它们可以作为所谓的轻量级事务运行。 You may find some pointers here.

标签: c# wcf iis transactions distributed-transactions


【解决方案1】:

确保 WCF 和 DB 服务器上的 DTC 安全设置如下:

【讨论】:

    猜你喜欢
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多