3

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

4

2 回答 2

4

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

于 2010-12-06T13:04:35.933 回答
0

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

于 2010-12-06T11:28:00.253 回答