Castle WCF 集成通道关闭
我的印象是,释放 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 Integration 时,如何正确关闭 WCF 连接通道/代理?
编辑
删除了使用LifeStyle.Singleton
(当容器被丢弃时释放通道)的提及,因为使用其他生活方式产生了相同的效果。
I've been under the impression that releasing the component for my WCF service connection would close the channel associated with the component. However, consider the following:
// 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);
...
}
}
I've tried various lifestyles including my own that inherits AbstractLifestyleManager
and calls base.Release(context)
but the channel remains open after the component is released. Is this expected behavior?
So how do I close then WCF connection channel/proxy properly when using Castle WCF Integration?
Edit
Removed mention of using LifeStyle.Singleton
(where channel is released when container is disposed) as using other lifestyles have yielded the same effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
container.Release(myService);
不会释放您的单例组件。通道将与组件一起释放,这在单例的情况下意味着当容器被处置时。container.Release(myService);
does not release your singleton component. Channel will be released along with the component which in case of singletons means when the container gets disposed.