当使用会话或事务性的单例服务时,使用易失资源管理器去管理状态,并且避免显示地使用状态编程或者在完整时依赖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.
保持异步调用操作简短。不要把异步调用和冗长的操作混淆。