快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

澳门威斯尼斯人娱乐平台_龟发之家论坛



本日收拾的内容是WCF事务和并发治理相关的设计规范。WCF办事编程设计规范(5):事务与并发治理设计。中英文对比,How to design Transactions and Concurrency Management in WCF Service.

下面一节是行列步队办事与安然。

Transactions

事务

1. Never manage transactions directly.

不要直接治理事务

2. Apply the TransactionFlow attribute on 澳门威斯尼斯人娱乐平台the contract, not the service class.

在左券而不是办事类上标注TransactionFlow属澳门威斯尼斯人娱乐平台性,

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.

应用本书中的术语,为客户端或客户端/办事端事务模式设置设置设备摆设摆设办事。避免应用None或办事事务模式。

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

应用本书中的术语,为办事或办事/回调事务模式设置设置设备摆设摆设回调。避免应用None或回调事务模式。

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

当应用客户端/办事或办事/回调模式,经由过程BindingRequirement属性约束绑定传播事务

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

在客户端,始终捕获None或办事事务里抛出的所有非常。

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.

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

当应用会话或事务性的单例办事时,应用易掉资本治理器去治理状态,并且避免显示地应用状态编程或者在完备时依附WCF实例钝化机制,

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

在持久性事务办事里,始终经由过程设置SaveStateInOperationTransaction 为true来把事务和传播到存储系统中。

Concurrency Management

并发治理

1. Always provide thread-safe access to:

对以下资本始终供给线程安然的造访

a) Service in-memory state with sessionful or singleton services

会话或者单例办事在内存中的状态

b) Client in-memory state during callbacks

回调时代客户端在内存中的状态

c) Shared resources

共享资本

d) Static variables

静态变量

2. Prefer ConcurrencyMode.Single (the default). It enables transactional access and provides thread safety without any effort.

默认环境保举应用ConcurrencyMode.Single模式。它会启用事务性造访并供给线程安然,而不会带来任何开销。

3. Keep operations on single-mode sessionful and singleton services short in order to avoid blocking other clients for long.

当操作在是单个会话模式或者单例模式时,请包管操作简短,以长光阴免壅闭客户端。

4. When using ConcurrencyMode.Multiple, you must use transaction autocompletion.

当应用ConcurrencyMode.Multiple时,你必须启用事务autocompletion自动提交机制。

5. Consider using ConcurrencyMode.Multiple on per-call services to allow concurrent calls.

在单调办事上应用ConcurrencyMode.Multiple属性,容许并发调用,

6. Transactional singleton service with ConcurrencyMode.Multiple must have ReleaseServiceInstanceOnTransactionComplete set to false:

应用ConcurrencyMode.Multiple的事务性单例办事必须把ReleaseServiceInstanceOnTransactionComplete 设置为 false

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,

ConcurrencyMode = ConcurrencyMode.Multiple,

ReleaseServiceInstanceOnTransactionComplete = false)]

class MySingleton : IMyContract

{...}

7. Never self-host on a UI thread, and have the UI application call the service.

不要在UI线程上托管办事,让UI法度榜样只调用办事。

8. Never allow callbacks to the UI application that called the service unless the callback posts the call using SynchronizationContext.Post().

从不容许办事回调UI法度榜样,除非回调应用了SynchronizationContext.Post().

9. When supplying the proxy with both synchronous and asynchronous methods, apply the FaultContract attribute only to synchronous methods.

当代理供给了异步和同步措施的时刻,在同步措施上应用FaultContract

10. Keep asynchronous operations short. Do not equate asynchronous calls with lengthy operations.

维持异步调用操作简短。不要把异步调用和冗长的操作肴杂。

11. Do not mix transactions with asynchronous calls.

不要把事务和异步调用混用

您可能还会对下面的文章感兴趣: