.NET 3.5, WCF

Contruct ChannelFactory takes too long with config

Recently we experienced an issue with a service where the first call took a long time to complete. Subsequent calls would complete fine and fast, but the first call took a long time. Using Service Trace Viewer told us that the problem lay at constructing ChannelFactory.


image


The detailed trace of this activity didn’t give us any more hints to what was causing the problem.


image


All we could see was that the time appeared to all disappear when WCF tries to get the configuration for service.


The code for this (I’m just using the automatically generated Service1 template to illustrate) was as follows:

proxy = new Service1Client();
Console.WriteLine(proxy.GetData(22));

This is strange indeeded. Since loading the config seemed to be the issue, we changed the code to do this programmatically instead.

EndpointAddress address = new EndpointAddress(“net.tcp://localhost/SimpleService/Service1“);
proxy = ChannelFactory<IService1>.CreateChannel(new NetTcpBinding(), address);

Running this and looking at the trace for this revealed that this was a much more performant way of doing this.


image


For the scenario we had this solution was fine – but it’s not really a solution, it’s a workaround.


I’m still at a loss to describe why this happened on these servers, since the same thing worked quite differently on other servers. There, both solutions performed the same. So this is obviously something connected to some setting or circumstance that differs on those servers when compared to others.


If anyone has insight into this, or suggestions, please share.

1 thought on “Contruct ChannelFactory takes too long with config”

  1. I have to admit, I haven’t tried it. I had the issue specifically in one envirnment at one customer and we worked around it. I haven’t had the opportunity to try another solution.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s