开发者

Castle WCF Integration Channel Closing

开发者 https://www.devze.com 2023-03-05 07:56 出处:网络
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:

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.Single开发者_开发技巧ton (where channel is released when container is disposed) as using other lifestyles have yielded the same effect.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号