WCF Transaction各種類型及設置方法介紹
WCF通過其強大的功能優勢,為我們實現了一個全新的跨平臺的企業級互聯應用平、解決方案。在WCF中實現多事務協調,需要多方面的協調。既涉及到binding協議的設置,又涉及到ServiceBehavior和OperationBehavior的設置。
我們知道,關于binging protocal涉及到WCF Transaction的有2個值,即TransactionFlow=true|false。在ServiceBehavior-level,涉及到Transaction的是TransactionFlowOption,其值有Allowed,NotAllowed,Mandatory共3個option。在OperationBehavior-level,涉及到Transaction的是TransactionScopeRequired,其值有True|false共2個。 因此,將其全部組合起來的話,產生的可能配置為2*3*2=12種。
用一個簡單的公式表示為:
- Transaction = TransactionFlow[True|false](binding protocal)
- +TransactionFlowOption[Allowed|NotAllowed|Mandatory](ServiceBehavior)
- +TransactionScopeRequired[True|false](OperationBehavior)
實際上,在這12種可能的配置中,有4種是相互矛盾的,因此剩下8種可能的配置。 My god,要配置一個事務還有8種可能的配置 :#t#
為了便于記憶,我們將剩余8種可能的配置分為4類,分別為:客戶/服務型事務(client/service transaction),客戶型事務(client transaction),服務型事務,非事務。
下面給出每種WCF中事務類型的典型配置
1.客戶/服務型事務
TransactionFlow=true(binding) + TransactionFlowOption=Allowed(ServiceBehavior) + TransactionScopeRequired=true(OperationBevior)
2.客戶型事務
TransactionFlow=true(binding) + TransactionFlowOption=Mandatory(ServiceBehavior) + TransactionScopeRequired=true(OperationBevior)
3 服務型事務
TransactionFlow=false(binding) + TransactionFlowOption=NotAllowed(ServiceBehavior) + TransactionScopeRequired=true(OperationBevior)
4 非事務
TransactionFlow=false(binding) + TransactionFlowOption=NotAllowed(ServiceBehavior) + TransactionScopeRequired=false(OperationBevior) 。簡單的講,如果發布一個service,不做任何WCF Transaction方面的設置,該Service就是nontransactional