Connection Wait Time
Hello,
I've been doing some wcf stuff lately. I had noticed that there is a wait-time for the first connection to get estabilished then everything is smooth.
(maybe unrelated but I installed a few windows updates yesterday) Now the first connection takes about 20 seconds! The server and the client are both on my dev box. Is there a way I can troubleshoot this issue?
Thanks
[408 byte] By [
h1] at [2008-1-6]
If by "first connection" you mean the first method call on a channel, the "wait-time" could be the channel opening. Often, a channel is open implicitly with the first method call. This makes that first method call seem to take longer than the others because it's opening the channel. If you explicitly open the channel before sending messages, each method call should take around the same amount of time. So, instead of this:
clientProxy.CallMethod();
Try this:
((IChannel)clientProxy).Open();
clientProxy.CallMethod();
-James
Thanks James,
But what I don't understand is how come it takes so long to open a channel specially when both consumer & service are running on my machine.
The are 2 other things:
1. I'm conusming multiple services. It is only the first method call on the first service that takes a long time.
2. This wasn't happening before, a 20 second wait time isn't normal...at least it wasn't till a day ago.
Has anyone else experienced similar problem?
Thanks
h1 at 2007-10-2 >

We are experiencing exactly the same problem. The first call to any service takes about 20 seconds and then calls to any other service are very quick.
We are not using a WCF Client Channel Pool so are stumped why this is happening.
I'm wondering if anyone can give me a hint as to what maybe happening here
Thanks,
Here is a code snippet that describes the way I'm calling my services
using
(ChannelFactory<IContract> factory = new ChannelFactory<IContract>("BasicHttpBinding_IContract")) {
try {
IContract service = factory.CreateChannel(); service.DoSomething() }
catch (Exception e)
{
//some loging and stuff
throw;
}
}
h1 at 2007-10-2 >

I'm still wondering if the delay is in the method call, or the opening of the channel.
What happens when you do this:
using (ChannelFactory<IContract> factory = new ChannelFactory<IContract>("BasicHttpBinding_IContract"))
{
try
{
IContract service = factory.CreateChannel(); ((IChannel)service).Open();
service.DoSomething()
}
catch (Exception e)
{
//some loging and stuff
throw;
}
}
You probably want to add some logging to see what takes longer in that code. Maybe print out DateTime.Now before the call to Open, then before and after service.DoSomething().
-James
Hello James,
I added the .Open() instruction and also instrumented (shown by LogTime psudo-code) the code in the following way:
LogTime
using (ChannelFactory<IContract> factory = new ChannelFactory<IContract>("BasicHttpBinding_IContract"))
{
try
{
LogTime1
IContract service = factory.CreateChannel();
LogTime2
((IChannel)service).Open();
LogTime3
service.DoSomething()
LogTime4
}
catch (Exception e)
{
//some loging and stuff
throw;
}
}
The result follow:
LogTime1:Create Channel:7/17/2007 7:13:39 PM
LogTime2:Open Service:7/17/2007 7:13:39 PM
LogTime3:Calling the method7/17/2007 7:14:01 PM
LogTime4:Returning from method7/17/2007 7:14:04 PM"string
As you can see it took 20 seconds to invoke the method...now from that point on, I can call any method on any other service and it works very quickly.
However, if don't use any of my services for some time. Then first call to any of the services will take 20 seconds again, then every other service-call is ok, until I wait for a while... Thanks
h1 at 2007-10-2 >

From those results, it looks like the 20 second delay occured between LogTime2 and LogTime3. The only code that executed there was opening the channel. I would venture to guess that the channel is closing after some period of inactivity, then when you call a method again, the channel is implicitly opened, taking 20 seconds or so. It might be worth configuring tracing at the service and client to further diagnose this.
-James