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.
The detailed trace of this activity didn’t give us any more hints to what was causing the problem.
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();
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.
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.