• [织梦吧]唯一域名:www.dedecms8.com,织梦DedeCMS学习平台.

当前位置: > 编程与数据库 > net编程 >

WCF服务编程设计规范(5):事务与并发管理设计(2)

来源: www.dedecms8.com 编辑:织梦吧 时间:2012-06-27点击:

//Avoid:避免
[OperationBehavior(TransactionScopeRequired = true)]
public void MyMethod()
{
try
{
...
}
catch
{
Transaction.Current.Rollback();
}
}

10If 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.

使用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.

对于会话服务,避免因为会话关闭时的auto-complete就把会话边界和事务边界等价。

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

尽量使用TransactionalBehavior属性去管理会话服务上的事务

[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.

About D8

  • ©2014 织梦吧(d8) DedeCMS学习交流平台
  • 唯一网址 www.DedeCMS8.com 网站地图
  • 联系我们 1170734538@qq.com ,  QQ