Like the title says, I'm curious to know what state is contained in a WCF client proxy object - should I be new'ing up tons of these casually and not caring? Or are they more heavyweight and I shouldn't be so cavalier about 开发者_如何学Pythoncreating them?
Not much really - the link to the communication channel, it's state - that's about it. WCF tends to be very much stateless, so both your client and the server won't really hang on to a lot of state.
The cost of client-side proxy generation is two-part:
first, there's a
ChannelFactory<T>
that needs to be created (whereT
is your service contract, e.g.IMyService
). This part is fairly heavyweight, so if you can, cache the channel factorysecond, the channel factory is used to create the actual channel - this is quite a simple operation, and you shouldn't bother to cache this.
If you've used the Add Service Reference
functionality in Visual Studio, or svcutil.exe
on the command line, you usually end up with a (YourService)Client
class - this basically encapsulates those two steps for you.
If you feel the urge to optimize, check out this two-step process and see if you can make it work for you, and if caching the factory (and thus limiting the number of factory instantiations) makes a difference for you.
精彩评论