I have a WCF service that I use in my code and is generated as a ChannelFactory class. I know that the correct way to consume WCF is to create a ChannelFactory (let this AwesomeClient), do the work, then call Close () on it. Here is my snippet:
public static void DoSomething()
{
var client = new AwesomeClient();
client.DoSomethingAwesome();
client.Close();
}
However, I expect DoSomething to be called quite often (say 10 times per minute?), So the advice I got is to create an instance of ChannelFactory as a static instance and always use the same instance and never use close it (because it is "cheaper" than always re-creating the ChannelFactory and then closing it).
I am here for a second opinion, can someone tell me why not calling Close and reusing a static instance is a good idea? Or should I just stick with the recreation of ChannelFactory and Close () for each call?
source
share