views:

637

answers:

1

I've been reading that ChannelFactory creation is expensive and that unless there is a technical reason not to, one should reuse ChannelFactories when possible either by caching them someway, or by using static instances of the factories.

In your experience, what ChannelFactory reuse strategies have you found to be the most useful and robust within the context of an ASP.NET application?

+2  A: 

If you're using .NET 3.0 SP1 and up and don't need special stuff that requires handling channels directly, then the best option would be to just use client-side proxy classes derived from ClientBase<T> (like the ones generated when importing services). Those already cache the factory underneath. See here for the details.

If not, then yeah, you'll need to stick the IChannelFactory<T> object somewhere, but you need to still make sure you handle sharing appropriately (I don't think there's any guarantees made by the stack that access of a factory is thread-safe), but other than that, it should be fairly straight-forward.

tomasr