WCF: Comparison between non-closing ChannelFactory and constantly re-creating ChannelFactory and closing it

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?

+3
source share
1 answer

10 times a minute is not so often. 10 times per second, I would definitely at least think about reusing the channel.

In your case, there are many unknowns to make the right decision. How many customers are going to connect to the service? What is the connection (there is a chance that it will decrease by a split second), is there load balancing? Proxy?

, , , ChannelFactory. , . factory .

+3

Source: https://habr.com/ru/post/1750541/


All Articles