WCF中的Instance Management2011-10-30 龚岑 我们很容易理解在旧有编程模型中关于类实例的内容。设计模式中Singleton 也就是在描述着档子事 。但基于WCF 并非适合于以上场景,Service 与Client 之间要保持良好的Instance 模型则需要依靠很多 其他机制。Programming WCF Service Chapter4 对此进行了细致的描述。(更多细节请自行阅读~)WCF 支持三种类型的Instance 管理:

1. pre-call services :每个客户端请求对应一个instance2. Sessionful services :每个客户端连接对应一个instance3. Singleton services :所有客户端共享一个instance利用Behaviors 可以解决这方面的问题(还有一些其他基于“ 服务端” 的其他方面的问题可以通过 使用behaviors 来解决)。注:客户端是不知道服务端设置了什么样的behaviors 的。VS2008MSDN :ms- help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.servicemodel/html/88efb135-d425-e5b1-57d6 -01a67158c1a5.htmApply the ServiceBehaviorAttribute attribute to a service implementation to specify service-wide execution behavior. (To specify execution behavior at the method level, use the OperationBehaviorAttributeattribute.) This attribute can be applied only to service implementations.