Wednesday, May 30, 2012

WCF Timeout Issues

When I first converted my SharePoint Webpart to use the locally deployed WCF service, no compile errors occured.

However, when I deployed the webpart and started testing, timeouts were occuring and the page was not responding.

Researched this and found the following information useful.​ http://stackoverflow.com/questions/981475/wcf-timeout-exception-detailed-investigation

This is what I did:

1)On the Sharepoint Web.config file on my development server: Set the following: maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" Also, in the clientcode(webpart code) did the following:

2) Set the following in In Page_load: //This says how many outgoing connection you can make to a single endpoint. Default Value is 2 System.Net.ServicePointManager.DefaultConnectionLimit = 200;

3)Made sure all the WCF client objects are closed in a finally block after the WCF calls are made. Even in cases where Channels were used, closed the channel in the finally after the WCF service call was made.
The close channel has the following code where _wcfAccess is the channel created.

if (_wcfAccess != null) { ((IClientChannel)_wcfAccess).Close(); ((IDisposable)_wcfAccess).Dispose(); _wcfAccess = null; }

Inspite of having all the above in place, I ran in to an issue where my web page froze up for an indefinite period of time.The page had a call to a WCF service that should return a record. I saw the "Server too busy" exception in the diagnostics log when the above happened.

I researched and stumbled on this thread. http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/745b95d2-1480-4618-89f5-1339d6ee228d/ I was going to try the above, when I found out the below. It turns out that there was a bug in the Database code that it was returning multiple records or a Dataset instead of one record.

The WCF call then took forever to finish receiving this and the Receive Timeout on the Binding Element for the WCF contract in question was set to 10 minutes(by default) and so the page froze up for this long.

No comments: