WCF net.tcp 绑定分布式事务超时问题

发布于 2024-10-06 05:10:50 字数 2555 浏览 5 评论 0原文

通过 WCF net.tcp 绑定运行分布式事务时,我遇到了奇怪的超时问题。交易总是在 10 分钟后超时。我想我已经将我知道的所有超时设置为比该值更高的值(15 分钟),但我可能忽略了一些事情。我正在调用 IIS7.5 中托管的 WCF net.tcp 服务。

在服务方面,我有以下绑定配置:

<binding name="OrgSyncService_NetTcpBinding" portSharingEnabled="true"
         transactionFlow="true" maxReceivedMessageSize="1048576000"
         openTimeout="00:01:00" receiveTimeout="00:15:00" sendTimeout="00:15:00">
    <security mode="Transport">
        <transport clientCredentialType="Windows"
                   protectionLevel="EncryptAndSign"/>
    </security>
    <readerQuotas maxStringContentLength="1073741824" />
    <reliableSession enabled="true" inactivityTimeout="00:15:00" />
</binding>

如您所见,所有相关超时均为 15 分钟。在客户端,绑定配置如下:

<binding name="NetTcpBinding_OrgSyncService" closeTimeout="00:01:00"
         openTimeout="00:01:00" receiveTimeout="00:15:00" sendTimeout="00:15:00"
         transactionFlow="true" transferMode="Buffered"
         transactionProtocol="OleTransactions"
         hostNameComparisonMode="StrongWildcard" listenBacklog="10"
         maxBufferPoolSize="524288" maxConnections="10"
         maxReceivedMessageSize="1048576000">
    <readerQuotas maxDepth="32" maxStringContentLength="1073741824"
                  maxArrayLength="16384" maxBytesPerRead="4096"
                  maxNameTableCharCount="16384" />
    <reliableSession ordered="true" inactivityTimeout="00:15:00" enabled="true" />
    <security mode="Transport">
        <transport clientCredentialType="Windows"
                   protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" />
    </security>
</binding>

同样,我知道的所有超时都设置为 15 分钟。最后是启动事务的代码:

var options = new TransactionOptions
{
    IsolationLevel = IsolationLevel.ReadCommitted,
    Timeout = TimeSpan.FromMinutes(15)
};
using (var ts = new TransactionScope(TransactionScopeOption.Required, options))
{
    // Do transactional work.
    // Call web service.
    service.HandleSourceChanges(listOfChanges);
    ts.Complete();
}

Web 服务方法本身具有以下签名:

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void HandleSourceChanges(IEnumerable<OrgSyncSourceChange> sourceChanges)
{ /* Handle changes and store them in the database. */ }

但是,正如我所说,在启动事务后正好 10 分钟,它就超时了。我不确定是交易本身超时了。可能是另一个超时的组件导致事务超时。

我缺少什么?是否有我不知道的 IIS 设置? MSDTC 设置?

I have a strange timeout problem when running a distributed transaction over a WCF net.tcp binding. The transaction always times out after exactly 10 minutes. I think I have set all the timeouts I know to a higher value than that (15 minutes) but I'm probably overlooking something. I'm calling a WCF net.tcp service that's hosted in IIS7.5.

On the service side, I have the following binding config:

<binding name="OrgSyncService_NetTcpBinding" portSharingEnabled="true"
         transactionFlow="true" maxReceivedMessageSize="1048576000"
         openTimeout="00:01:00" receiveTimeout="00:15:00" sendTimeout="00:15:00">
    <security mode="Transport">
        <transport clientCredentialType="Windows"
                   protectionLevel="EncryptAndSign"/>
    </security>
    <readerQuotas maxStringContentLength="1073741824" />
    <reliableSession enabled="true" inactivityTimeout="00:15:00" />
</binding>

As you can see, all relevant timeouts are 15 minutes. On the client-side, the binding configuration is as follows:

<binding name="NetTcpBinding_OrgSyncService" closeTimeout="00:01:00"
         openTimeout="00:01:00" receiveTimeout="00:15:00" sendTimeout="00:15:00"
         transactionFlow="true" transferMode="Buffered"
         transactionProtocol="OleTransactions"
         hostNameComparisonMode="StrongWildcard" listenBacklog="10"
         maxBufferPoolSize="524288" maxConnections="10"
         maxReceivedMessageSize="1048576000">
    <readerQuotas maxDepth="32" maxStringContentLength="1073741824"
                  maxArrayLength="16384" maxBytesPerRead="4096"
                  maxNameTableCharCount="16384" />
    <reliableSession ordered="true" inactivityTimeout="00:15:00" enabled="true" />
    <security mode="Transport">
        <transport clientCredentialType="Windows"
                   protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" />
    </security>
</binding>

Again, all timeouts that I'm aware of are set to 15 minutes. Finally, the code that starts the transaction:

var options = new TransactionOptions
{
    IsolationLevel = IsolationLevel.ReadCommitted,
    Timeout = TimeSpan.FromMinutes(15)
};
using (var ts = new TransactionScope(TransactionScopeOption.Required, options))
{
    // Do transactional work.
    // Call web service.
    service.HandleSourceChanges(listOfChanges);
    ts.Complete();
}

The web service method itself has the following signature:

[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void HandleSourceChanges(IEnumerable<OrgSyncSourceChange> sourceChanges)
{ /* Handle changes and store them in the database. */ }

But, as I said, exactly 10 minutes after starting the transaction, it times out. I'm not sure it's the transaction itself that times out. It could be another component that times out that causes the transaction to time out.

What am I missing? Is there an IIS setting I don't know about? An MSDTC setting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

放飞的风筝 2024-10-13 05:10:50

经过长时间的搜索,我自己找到了解决方案。事实证明,它是 machine.config 中的默认值。其中有一个 system.transaction 部分,默认事务超时值为 10 分钟。该超时优先于所有其他超时。

如果将以下内容添加到您的machine.config(在我的例子中为C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config),您可以修改此全局超时限制。

<system.transactions>
    <machineSettings maxTimeout="00:15:00" />
</system.transactions>

在本例中,我将其设置为 15 分钟。

I found the solution myself after a long search. It turned out to be a default value in machine.config. There's a system.transaction section there with a default transaction timeout value of 10 minutes. This timeout overrides all other timeouts.

If you add the following to your machine.config (in my case in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config) you can modify this global timeout limit.

<system.transactions>
    <machineSettings maxTimeout="00:15:00" />
</system.transactions>

In this case I set it to 15 minutes.

<逆流佳人身旁 2024-10-13 05:10:50

这可能是 IIS 中应用程序池中的空闲超时设置吗?也许值得扩展这个?

Could it be the idle-time out setting in your App Pool in IIS? Maybe worth extending this?

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