When your WCF service stops responding

by Matthew Noonan 19. February 2008 00:00

My venture into WCF is proving to be quite educational, in some ways more stressful than others. Today I had a client trying to run a demo, but their service calls were routinely locking up and they kept having to restart the web server. So much for having a day off...  :-(

So I drove to the client, fired up my WCF test harness, ran a couple of tests and everything seemed to be working just fine. So I loaded up the AJAX-driven web site, and sure enough I could make the service lock up after just a few callbacks to the server. Back to my test harness, only this time I decided to add some looping in order to simulate the multiple calls made by the web browser. This time, I was able to lock up the service in my test harness as well.

So what was the solution?

It turns out that when you create the proxy for the service call, it is very important that you also call Dispose(). I guess I got a little lazy and tried to count on the garbage collection to take care of it, but my code was actually starving the service pool of available threads, and so it stops responding until the web server is restarted or the application pool cycles.

So I'm posting this here hoping that others will learn from my mistake: make sure you call Dispose() directly on your service proxy object, or use the "using" statement which will do it for you automatically.

 

HelloServiceClient proxy = new HelloServiceClient();
string result = proxy.HelloWorld(textBox1.Text);
proxy.Close();
proxy.Dispose();
 

-- OR --

 

using (HelloServiceClient proxy = new HelloServiceClient()) 
{ 
    string result = proxy.HelloWorld(textBox1.Text); 
}

 

In my next post, I will review the WCF support now in EasyObjects. Way cool.

kick it on DotNetKicks.com

 

Tags:

WCF

Comments

3/19/2008 2:25:50 PM #

Thanks. I got stuck exactly as described! Didn't have a clue till I read your blog. I used Close and that did it. Dispose wasn't available on my client!

victor United Kingdom

5/20/2008 6:20:47 AM #

I faced the same problem with FirebirdSQL - same thing.
It´s a good school for using ressources in a reasonable way.

Tagesgeld Germany

7/28/2008 7:24:31 PM #

Good post thanks!  Ran into the same issue in my app.  Dispose was also not a option with my proxy but the using(myproxy){....} worked just fine.

cmertz United States

8/8/2008 9:04:35 PM #

When I switched from using svcutil to using "Add Service Reference", the problem you described popped up. Apparently the proxies generated by svcutil won't persist while those generated by "Add Service Reference" will... Anyway, I switched all my proxy initializations to "using" statements and the client now works like a charm. Thank you!

mmagnitz Germany

8/29/2008 7:10:58 AM #

Same problem here! Thanks for the tip! You're a life saver!

Alex Dresko United States

9/20/2008 2:22:55 AM #

Same issue here. And YOU probably saved me a few hours of searching. Thanks!

Webdesign Germany

10/12/2008 10:42:53 AM #

Thank you!!!!!

Charles

1/26/2009 6:00:45 PM #

You are a complete lifesaver! Got my app fixed minutes before a customer demo, wish I could buy you a pint Smile

Jon United Kingdom

1/26/2009 7:49:09 PM #

I'm always up for a pint, bro!

mgnoonan United States

1/28/2009 12:23:55 AM #

Thaaaaaaaaaanks !!!

mops Slovenia

Comments are closed