分享方式:


以單一併行模式排序處理訊息

WCF 不會保證訊息的處理順序,除非基礎通道是具有回話狀態的。 例如,使用不是會話通道之 MsmqInputChannel 的 WCF 服務將無法依序處理訊息。 在某些情況下,開發人員可能會想要依序處理行為,但不想使用會話。 本主題描述當服務以單一併行模式執行時,如何設定此行為。

依序訊息處理

名為 EnsureOrderedDispatch 的新屬性已新增至 ServiceBehaviorAttribute。 當 EnsureOrderedDispatch 設定為 true 且 ConcurrencyMode 設定為 Single 傳送至服務的訊息時,將會依序處理。 下列代碼段說明如何設定這些屬性。

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, EnsureOrderedDispatch = true )]  
    class Service : IService  
    {  
         // ...  
    }  

如果 ConcurrencyMode 設定為任何其他值, InvalidOperationException 則會擲回 。

另請參閱