【发布时间】:2011-08-24 14:07:14
【问题描述】:
我的印象是,为我的 WCF 服务连接释放组件会关闭与该组件关联的通道。但是,请考虑以下事项:
// In some installer class
public void Install(IWindsorContainer container, IConfigurationStore store) {
container.Register(
Component.For<IMyService>()
.Forward<IMyOtherService>()
.AsWcfClient(WcfEndpoint.FromConfiguration("WSHttpBinding_IMyService"))
.LifeStyle.Transient
);
}
// In some local class enabling constructor injection for IMyService
public void DoStuff() {
IWindsorContainer container = GetContainer();
var myService = container.Resolve<IMyService>();
if(myService != null) {
container.Release(myService);
// I had always thought this shouldn't work
// as the channel should be closed - but its
// state is Opened
var foo = myService.GetSomething( ... );
DoOtherStuff(foo);
...
}
}
我尝试了各种生活方式,包括我自己的生活方式,它继承了AbstractLifestyleManager 并调用了base.Release(context),但在组件发布后频道仍然保持打开状态。这是预期的行为吗?
那么在使用 Castle WCF 集成时如何正确关闭 WCF 连接通道/代理?
编辑
删除了使用LifeStyle.Singleton(在处置容器时释放通道)作为使用其他生活方式产生相同效果的提及。
【问题讨论】:
标签: c# wcf castle-windsor integration castle