Pergunta

I'm using WCF to create a connection beween a server app and client app.

Because I'm using NetTcpBinding, I want to keep alive the channel created by:

T proxy = ChannelFactory<T>.CreateChannel();

I bring the proxy instance into my app to communicate with server. At some moment, I renew this proxy, with a different factory. But I want to release resources from the first factory, by disposing it. But I don't wan't to manage factories and keep a reference to.

Is there a way with the proxy instance to retrive the channel associate to dispose it ?

Like ...

var commObj = (ICommunicationObject)proxy;
commObj.Factory.Dispose();

Thanks

Foi útil?

Solução

Unfortunately, it is not possible, because Channels and Factories are not linked. But I think your approach is not correct. You should keep a reference to the factory and create Channel as needed. Re-using Channel can be a problem in some cases. A channel can be faulted, but the inner factory will still be valid. Creating a factory has a real cost, and some .net 3.5 SP1, factories are internally stored in a static cache.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top