Transactions

  1. Never manage transactions directly.

  2. Apply the TransactionFlow attribute on the contract, not the service class.

  3. Do not perform transactional work in the service constructor.

  4. Using this book's terminology, configure services for either Client or Client/Service transactions. Avoid None or Service transactions.

  5. Using this book's terminology, configure callbacks for either Service or Service/Callback transactions. Avoid None or Callback transactions.

  6. When using the Client/Service or Service/Callback mode, constrain the binding to flow transactions using the BindingRequirement attribute.

  7. On the client, always catch all exceptions thrown by a service configured for None or Service transactions.

  8. Enable reliability and ordered delivery even when using transactions.

  9. In a service operation, never catch an exception and manually abort the transaction:

    //Avoid:
    [OperationBehavior(TransactionScopeRequired = true)]
    public void MyMethod(  )
    {
       try
       {
          ...
       }
       catch
       {
          Transaction.Current.Rollback(  );
       }
    }
  10. If you catch an exception in a transactional operation, always rethrow it or another exception.

  11. Keep transactions short.

  12. Always use the default isolation level of IsolationLevel.Serializable.

  13. Do not call one-way operations from within a transaction.

  14. Do not call nontransactional services from within a transaction.

  15. Do not access nontransactional resources (such as the filesystem) from within a transaction.

  16. With a sessionful service, avoid equating the session boundary with the transaction boundary by relying on auto-complete on session close.

  17. Strive to use the TransactionalBehavior attribute to manage transactions on sessionful services:

    [Serializable]
    [TransactionalBehavior]
    class MyService : IMyContract
    {
       public void MyMethod(  )
       {...}
    }
  18. When using a sessionful or transactional singleton, use volatile resource managers to manage state and avoid explicitly state-aware programming or relying on WCF's instance deactivation on completion.

  19. With transactional durable services, always propagate the transaction to the store by setting SaveStateInOperationTransaction to true.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.210.102