none
ChannelFactory: New Connection each time? RRS feed

  • Question

  • Hi everyone,

    The code below generates a new ChannelFactory each time (I know about caching and the different setups).

    This is a windows services connecting to a local WCF server.

    This method is called a lot of times in a few minutes time.

    Here is the weird thing: on my computer this opens 2 connect but on someone elses computer this opens a new connection on a new port each time until we get "insufficient winsock resources available" then everything stops working. No internet connection, no network,.... he has to reboot! It seems he has run out of ports to open another.

    The only difference I can't thing of is that the WCF is running on a different port on his computer...

    What could be the reason for this?

    I can't cache the chanelfactory for know...

      public class CategoryCodeClientDelegate : ICategoryCodeService
        {
            private const string ConfigName = "EnterpriseCategoryBackend.NetTcpBinding_ICategoryCodeService";
    
            public EnterpriseCategoryCodeList ListEnterpriseCategoryCode(EnterpriseCategoryCodeSearch eNccSearch)
            {
                EnterpriseCategoryCodeList retval = null;
                using (ChannelFactory<ICategoryCodeService> factory = 
                            new ChannelFactory<ICategoryCodeService>(ConfigName))
                {
                    factory.Open();
    
                    ICategoryCodeService proxy = factory.CreateChannel();
    
                    retval = proxy.ListEnterpriseCategoryCode(eNccSearch);
    
                    factory.Close();
                }
                return retval;
            }
        }

    • Moved by KareninstructorMVP Tuesday, June 10, 2014 2:08 PM Moving from C# to WCF forum for better support
    Tuesday, June 10, 2014 10:55 AM

Answers

  • You also need close channel.  The common pattern is to cache channel factory but to close channel every time.

    ICategoryCodeService proxy = factory.CreateChannel();
    using(retval as IDisposable)
    {
        retval = proxy.ListEnterpriseCategoryCode(eNccSearch);
    }


    Wednesday, June 11, 2014 6:30 AM