WCF服务编程设计规范(6):队列服务、安全和服务总线

前端之家收集整理的这篇文章主要介绍了WCF服务编程设计规范(6):队列服务、安全和服务总线前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
WCF服务编程设计规范(6):队列服务、安全和服务总线。本节整理队列服务(Queue Servuce)、服务安全(Service Security)和服务总线(Service Bus)的设计规范。
@H_301_4@ Queued Services
@H_301_4@ 队列服务
@H_301_4@ 1. On the client,always verify that the queue (and a dead-letter queue,when applicable) is available before calling the queued service. Use QueuedServiceHelper.VerifyQueues() for this purpose.
@H_301_4@ 在客户端,在调用队列服务以前,始终检查队列是否可用(如果可以的话,也包括确认死信队列)。使用 QueuedServiceHelper.VerifyQueues() 方法检查。
@H_301_4@ 2. Always verify that the queue is available when hosting a queued service (this is done automatically by ServiceHost<T> ).
@H_301_4@ 当托管队列服务的时候始终检查队列是否可用( ServiceHost<T> 自动检测)
@H_301_4@ 3. Except in isolated scenarios,avoid designing the same service to work both queued and non-queued.
@H_301_4@ 除了某些单独的场景,避免避免在同一个服务里同时使用队列和非队列服务 @H_301_4@ 4. The service should participate in the playback transaction. @H_301_4@ 服务应该参与到回放事务中 @H_301_4@ 5. When participating in the playback transaction,avoid lengthy processing in the queued service. @H_301_4@ 当参与到回放事务里,避免队列服务里出现冗长的处理工作 @H_301_4@ 6. Avoid sessionful queued services. @H_301_4@ 避免使用会话性队列服务 @H_301_4@ 7. When using a singleton queued service,use a volatile resource manager to manage the singleton state. @H_301_4@ 当使用单例队列服务时,使用易失资源管理器去管理单例状态 @H_301_4@ 8. When using a per-call queued service,explicitly configure the contract and the service to be per-call and sessionless: @H_301_4@ 当使用单调队列服务时,明确设置服务和契约的单调和非回话属性 @H_301_4@ [ServiceContract(SessionMode = SessionMode. NotAllowed )] @H_301_4@ interface IMyContract @H_301_4@ {...} @H_301_4@ [ServiceBehavior(InstanceContextMode = InstanceContextMode. PerCall )] @H_301_4@ class MyService : IMyContract @H_301_4@ {...} @H_301_4@ 9. Always explicitly set contracts on a queued singleton to disallow sessions: @H_301_4@ 始终禁止在单例队列服务模式下使用会话 @H_301_4@ [ServiceContract(SessionMode = SessionMode. NotAllowed )] @H_301_4@ interface IMyContract @H_301_4@ {...} @H_301_4@ [ServiceBehavior(InstanceContextMode = InstanceContextMode. Single )] @H_301_4@ class MyService : IMyContract @H_301_4@ {...} @H_301_4@ 10. The client should call a queued service inside a transaction. @H_301_4@ 客户端应该在一个事务内部调用队列服务 @H_301_4@ 11. On the client side,do not store a queued service proxy in a member variable. @H_301_4@ 在客户端,不要在成员变量里存储队列服务的代理 @H_301_4@ 12. Avoid relatively short values of TimeToLive ,as they negate the justification for a queued service. @H_301_4@ 避免使用相对短的 TimeToLive 值,因为这会干扰队列服务的决策 @H_301_4@ 13. Avoid nontransactional queues. @H_301_4@ 避免非事务性队列 @H_301_4@ 14. When using a response queue,have the service participate in the playback transaction and queue the response in that transaction. @H_301_4@ 当使用一个应答队列时,让服务参与到一个回放事务中,并且在事务里,把应答消息装入队列。 @H_301_4@ 15. Have the response service participate in the response playback transaction. @H_301_4@ 让应答服务参与到应答回放事务里 @H_301_4@ 16. Avoid lengthy processing in a queued response operation. @H_301_4@ 避免在应答操作里进行冗长的处理工作 @H_301_4@ 17. With MSMQ 3.0,prefer a response service to a poison queue service dealing with failures of the service itself. @H_301_4@ 对于 MSMQ3.0, 推荐使用应答服务来处理服务自身失败,而不是毒信队列 @H_301_4@ 18. With MSMQ 4.0,use ReceiveErrorHandling.Reject for poison messages unless you have advanced processing with ReceiveErrorHandling.Move . @H_301_4@ Avoid ReceiveErrorHandling.Fault and ReceiveErrorHandling.Drop MSMQ4.0, 除非对 ReceiveErrorHandling.Move 有高级处理,否则为毒信队列使用 ReceiveErrorHandling.Reject 避免使用 ReceiveErrorHandling.Fault ReceiveErrorHandling.Drop @H_301_4@ 19. With MSMQ 4.0,consider the use of a response service to handle service playback failures. @H_301_4@ 考虑使用应答服务去处理服务回放错误 @H_301_4@ 20. Unless dealing with a sessionful contract and service,never assume the order of queued calls. @H_301_4@ 除非处理会话契约和服务,否则从不假定队列调用是有序的 @H_301_4@ 21. Avoid multiple service endpoints sharing a queue. @H_301_4@ 避免多个服务终结点共享一个队列 @H_301_4@ 22. Avoid receive context. @H_301_4@ 避免使用接收上下文环境 @H_301_4@ Security @H_301_4@ 安全 @H_301_4@ 1. Always protect the message and provide for message confidentiality and integrity. @H_301_4@ 始终保护消息,并为消息提供安全性和完整性 @H_301_4@ 2. In an intranet,you can use Transport security as long as the protection level is set to EncryptAndSign 在企业网内,只要你把保护级别设置为 EncryptAndSign 你可以使用传输安全, @H_301_4@ 3. In an intranet,avoid impersonation. Set the impersonation level to TokenImpersonationLevel.Identification 在企业网内,避免使用 impersonation ,把 impersonation 级别设置为 TokenImpersonationLevel.Identification @H_301_4@ 4. When using impersonation,have the client use TokenImpersonationLevel.Impersonation 当使用 impersonation 时,让客户端使用 TokenImpersonationLevel.Impersonation @H_301_4@ 5. Use the declarative security framework and avoid manual configuration. @H_301_4@ 使用声明式安全框架,并避免手动配置 @H_301_4@ 6. Never apply the PrincipalPermission attribute directly on the service class: @H_301_4@ 从不在服务上直接设置 PrincipalPermission 属性 @H_301_4@ //Will always fail: @H_301_4@ [PrincipalPermission(SecurityAction.Demand,Role = "...")] @H_301_4@ public class MyService : IMyContract @H_301_4@ {...} @H_301_4@ 7. Avoid sensitive work that requires authorization at the service constructor. @H_301_4@ 避免在服务构造函数 完成需要授权的工作 @H_301_4@ 8. Avoid demanding a particular user,with or without demanding a role: @H_301_4@ 避免要求一个特定的用户,不管是否要求的角色 @H_301_4@ //Avoid: @H_301_4@ [PrincipalPermission(SecurityAction.Demand,Name = "John")] @H_301_4@ public void MyMethod() @H_301_4@ {...} @H_301_4@ 9. Do not rely on role-based security in the client’s callback operations. @H_301_4@ 不要在客户端回调操作里依赖基于角色的安全 @H_301_4@ 10. With Internet clients,always use Message security. @H_301_4@ Internet 客户端,始终使用消息安全 @H_301_4@ 11. Allow clients to negotiate the service certificate (the default). @H_301_4@ 运行客户端与服务端进行证书协商(默认) @H_301_4@ 12. Use the ASP.NET providers for custom credentials. @H_301_4@ 自定义客户端凭据使用 ASP.NET providers @H_301_4@ 13. When developing a custom credentials store,develop it as a custom ASP.NET provider. @H_301_4@ 当开发自定义客户端凭据存储的时候,使用自定义 ASP.NET provider. @H_301_4@ 14. Validate certificates using peer trust. @H_301_4@ 使用对等信任验证证书 @H_301_4@ The Service Bus @H_301_4@ 服务总线 @H_301_4@ 1. Prefer the TCP relay binding. @H_301_4@ 推荐使用 TCP Relay 绑定 @H_301_4@ 2. Make your services be discoverable. @H_301_4@ 让你的服务是可以被发现 @H_301_4@ 3. Do use discrete events. @H_301_4@ 使用分离事件 @H_301_4@ 4. Do not treat buffers as queues. @H_301_4@ 不要把缓存当做队列 @H_301_4@ 5. With buffers,avoid raw WCF messages and use the strongly typed,structured calls technique of BufferedServiceBusHost<T> and BufferedServiceBusClient<T> 对于缓存,避免原始的 WCF 消息以及使用强类型、结构化的 BufferedServiceBusHost<T> BufferedServiceBusClient<T> 调用方法 @H_301_4@ 6. Use message security. @H_301_4@ 使用消息安全 @H_301_4@ 7. Do not use service bus authentication for user authentication. @H_301_4@ 不要是有服务总线验证去做用户验证的工作 @H_301_4@ 8. Strive for anonymous calls and let the service bus authenticate the calling application. @H_301_4@ 争取匿名调用,并且让服务总线验证调用程序

猜你在找的设计模式相关文章