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.