ChannelFactory Reuse Strategies
Asked Answered
A

2

3

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?

Attemper answered 15/5, 2009 at 20:0 Comment(0)
M
3

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.

Moiramoirai answered 15/5, 2009 at 22:49 Comment(0)
S
1

Darin Damitrov posted a useful answer around re-use of channelfactories here:-

creating WCF ChannelFactory<T>

I've been looking at memory usage and performance in an application I've been working on recently. I applied the technique he advocated (using a dictionary to store a set of channelfactories) and had a good performance bump with it.

What I was seeing was that instantiating a channelfactory could take up to 70ms. If this is happening a lot it adds up quickly.

Currently, I'm being cautious and have not set up my DI container to serve up the same instances of the channelfactories for the lifetime of the application. Instead, I make them live for the duration of a single HTTP request (within which there may be many back-end service calls made).

Sholem answered 18/12, 2012 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.