问题
In inherited a project that uses a ChannelFactory instead of a Client for WCF calls. Why would you do that?
Also, is it safe to cache the result of a ChannelFactory.CreateChannel() call or should you create a new one each time?
回答1:
Creating the WCF client is a two-step process:
- creating the channel factory
- using that channel factory, create the actual channel
Step 1 is rather expensive in terms of processing power and speed - so if you can create the channel factory and then cache is somewhere, you can save yourself a bit of resources and create a channel off that cached channel factory will be faster than re-creating the whole client all the time.
So in this setup, I would try to cache the ChannelFactory
, if you can - and re-create the channel from that factory every time you need it.
来源:https://stackoverflow.com/questions/4888880/wcf-silverlight-why-use-a-channelfactory-instead-of-a-client