2010-12-06 101 views
3

當通過WCF net.tcp綁定運行分佈式事務時,我有一個奇怪的超時問題。恰好10分鐘後,交易總是超時。我認爲我已將所有超時設置爲比我知道的更高的值(15分鐘),但我可能忽略了某些內容。我正在調用IIS7.5中託管的WCF net.tcp服務。通過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

經過長時間的搜索,我找到了解決方案。它原來是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分鐘。

+0

奇怪的是,這覆蓋了你的配置中的值。一個要記住 – 2010-12-06 13:38:51

0

它可能是在您的應用程序池在IIS中的空閒超時設置?也許值得延長這一點?

+0

我自己找到答案。幾分鐘後再添加它。這不是空閒超時設置。 – 2010-12-06 12:58:26