Reuse of WCF Binding class instances

369 Views Asked by At

I create NetTcpBinding-s on application's client side in code just after aplication started and then use it to create channel factory via

new ChannelFactory<TService>(binding, address)

constructor.

Is it correct to pre-cache these NetTcpBinding instances in some List[NetTcpBinding] collection and then use elements of this collection to create ChannelFactory multiple times? Does WCF every time automatically reset binding timeouts etc.?

Is it safe at all or it is more safe to create new binding instance to every client call?

1

There are 1 best solutions below

0
On

Well... you should think about binding as a configuration, and nothing more.

Does WCF every time automatically reset binding timeouts etc.?

Don't need to. Timeouts are connection/channel properties which are set based on binding properties.

Is it safe at all or it is more safe to create new binding instance to every client call?

Theoreticaly it's safe, but keep in mind that if you're going to use instanced bindings then from default ChannelFactory will not use cache to store factory instances (expensive operation).