Contruct ChannelFactory takes too long with config

Listen with webReader
Published 15 October 09 09:14 PM | Johan Hedberg

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.

Filed under: ,

Comments

# Steve said on October 16, 2009 02:15 PM:

I have a similar issue when I create my ServiceHost for my WCF service.

On my home PC, it takes under a second.  At work, it takes 3-4 minutes to create the ServiceHost object.

All this time is spent loading up configuration, even though I'm not using configuration XML but coding the ServiceHost creation.

I'm completely stumped, I must admit.  I even coded a simple Hello World service with one operation returning a string, and takes the same amount of time.

Any ideas as to why configuration loading takes such an inordinate amount of time on some machines would also be very welcome for me.

# Harvey said on April 1, 2010 04:46 AM:

I had the same issue. I have resolved it by add

<configuration>

<runtime>

<generatePublisherEvidence enabled="false"/>

</runtime>

</configuration>. This will speed up the loading of assemblies. Check out blogs.msdn.com/.../startup-performance-disable-the-generatepublisherevidence-property.aspx.

# Johan Hedberg said on April 1, 2010 08:23 AM:

Thanks alot Harvey, given time I'll try that in my environment as well to see if that is an alternative solution to my problem.

# wsmith said on July 14, 2010 09:18 AM:

Hi,Johan. Does Harvey's solution solve the first call slow problem?

Please let me know. Send me samdothk#gmail.com.

Thanks in advance.

# Johan Hedberg said on July 27, 2010 09:10 AM:

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.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

News

    Messenger

    Twitter Updates

      Follow me on twitter

      Visitors

      Feedburner Subscribers

      Locations of visitors to this page

      Disclaimer

      All material is provided AS IS voiding any thinkable or unthinkable effect it might have for any use whatsoever. There... is that clear enough ;)

      Pages

    Syndication