我正在从事涉及金融交易的项目。
可以同时进行任意数量的交易。
问题是,似乎在少数情况下,交易以不可预测的方式“混淆”。我不知道这是否是我们的结果“不好” Lifestyle choices Castle Windsor或其他代码导致它。
希望清除Castle Windsor上的空气。
日志记录显示有时特定请求会与不同的响应混在一起。
我知道......也吓到了我们!
使用的主要技术是C#4,Net 4.5,WCF,Castle Windsor
结构如下:
container.Register(Component.For<IServiceA>().ImplementedBy<ServiceA>().LifestyleSingleton()); container.Register(Component.For<IServiceBFactory>().ImplementedBy<ServiceBFactory>().LifestyleSingleton());
container.Register(Component.For<IServiceB>().ImplementedBy<ServiceB>().LifestyleSingleton()); container.Register(Component.For<IServiceC>().ImplementedBy<ServiceCClient>().LifestyleSingleton());
container.Register(Component.For<IServiceC>().ImplementedBy<ServiceC>().LifestyleSingleton());
+-----------------------+ +-----------------------+ +-----------------------+ | | | | | | | | | | | | | [WCF Service A] | | [WCF Service B] | | [WCF Service C] | | Instantiates a +------------->+ Instantiates a +----------------> | Connects to an external | client to B using | | client to C using | | RESTful API | | ChannelFactory | | a serivice referece | | (Singleton Lifestyle) | | (Singleton Lifestyle) | | to C | | | | | | (Singleton Lifestyle) | | | | | | | | | +-----------------------+ +-----------------------+ +-----------------------+
更新1
现在通过related SO question,同时会仔细尝试所有建议
答案 0 :(得分:1)
您的问题可能是您同时从多个线程使用每个服务的单个实例。任何实例级别状态,无论是在您的代码中还是在您的服务体系结构中(例如,调用上下文),都将由对服务的所有调用进行共享和编辑。正如评论中所提到的,Transient
生活方式会有所帮助,但也有专门针对WCF的生活方式,例如PerWcfOperation
。