Castle WCF 集成通道关闭

发布于 2024-11-07 02:50:13 字数 1229 浏览 0 评论 0原文

我的印象是,释放 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2024-11-14 02:50:13

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文