2011-10-05 39 views
2

如果事務感知綁定啓用了事務流並且操作Op1具有TransactionFlowOption.Allowed,是否有可能使操作Op1調用的不同操作Op2不參與事務,操作Op2中也從來沒有回退的情況下,在操作OP1從事務中排除操作

插圖

// Op1: LogOnUser 
OperationBehavior(TransactionScopeRequired = true)] 
public bool LogOnUser(String username, String password) 
{ 
    // AuditWriteProxy declaration and instantiation 
    var valid = false; 

    /* Validation logic */ 

    // If validation failed 
    if(!valid) 
    { 
     // Invoke an op in an Audit Service. 
     // Op2 = AuditService.Write 
     // **MUST NOT BE ROLLED BACK EVEN AFTER WE [throw]** 
     AuditServiceProxy.Write("Authentication failed for user " + username); 

     throw new FaultException<AuthenticationFault>("Validation failed"); 
     // After throw, we expect everything transactional to rollback 
    } 

    AuditServiceProxy.Write("User " + username + " authenticated successfully"); 

    return true; 
} 

注意一些失敗:

  1. AuditService.Write操作使用msmq綁定並且是單向的
  2. 我試着對AuditService.Write操作合同上的TransactionFlowOption.NotAllowed以及TransactionScopeRequired = false的實現。

回答

5
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) 
{ 
    AuditServiceProxy.Write("Authentication failed for user " + username); 
} 

或將這種抑制代碼爲NonTransactionalLoggingService方法調用

+0

米奇感謝您的幫助。我已經試過了,它工作。我覺得有點笨 - 應該問自己什麼TransactionScopeOption.Suppress做:) –