Given a transaction-aware binding with transaction flow enabled and an operation Op1 that has TransactionFlowOption.Allowed, is it possible to make a different operation Op2 invoked from operation Op1 not participate in the transaction such that whatever operation Op2 does never rolls back in case something fails in operation Op1
Illustration
// 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;
}
Notes:
You can use TransactionScopeOption.Suppress
in a TransactionScope
:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
{
AuditServiceProxy.Write("Authentication failed for user " + username);
}
or place this suppression code into a NonTransactionalLoggingService
method call
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With