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