【问题标题】:Timeout problem in distributed transaction over WCF net.tcp bindingWCF net.tcp 绑定分布式事务中的超时问题
【发布时间】:2011-05-20 20:38:29
【问题描述】:

通过 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 设置?

【问题讨论】:

    标签: wcf transactions msdtc net.tcp


    【解决方案1】:

    经过长时间的搜索,我自己找到了解决方案。原来是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 分钟。

    【讨论】:

    • 奇怪的是,这会覆盖您配置中的值。一个要记住的
    • 没错。我花了大约半天时间才弄清楚这一点。这并不是一个有据可查的功能。
    【解决方案2】:

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

    【讨论】:

    • 我自己找到了答案。几分钟后添加。这不是空闲超时设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多