sharepoint-2010sharepoint-clientobject

Sharepoint Client model - request timeout


I am receiving a timeout from the Sharepoint Client Managed Object model.

Microsoft.SharePoint.Client.ServerException: The operation has timed out.

Basically, I am batching 100 updates and sending them at one go. It is no problem for me if takes time but I really want to avoid timeout exception.

I have tried in a million of ways to increase the timeout in the client context but they were all without success. I have used reflection to try to identity what the sharepoint is doing when calling the executequery method of the client context. sharepoint is basically creating an HttpWebRequest and sending it.

I have ended with the below code, but still without success:

 public static void SetInfinteTimeout(this ClientContext ctx)
{
    int timeout = 10 * 60 * 1000;
    ctx.RequestTimeout = timeout;
    ctx.PendingRequest.RequestExecutor.RequestKeepAlive = false;            
    ctx.PendingRequest.RequestExecutor.WebRequest.KeepAlive = false;
    ctx.PendingRequest.RequestExecutor.WebRequest.Timeout = timeout;
    ctx.PendingRequest.RequestExecutor.WebRequest.ReadWriteTimeout = timeout;            
    System.Net.ServicePointManager.DefaultConnectionLimit = 200;
    System.Net.ServicePointManager.MaxServicePointIdleTime = 2000;
    System.Net.ServicePointManager.MaxServicePoints = 1000;
    System.Net.ServicePointManager.SetTcpKeepAlive(false, 0, 0); 
    ServicePointManager.DnsRefreshTimeout = timeout; // 10 minutes       

}

But I am still receiving a timeout error!
Is there anything else that I am missing please?


Any assistance would be greatly appreciated.


Solution

  • The solution was to use clientcallablesettings (SPWebApplication.ClientCallableSettings):
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.clientcallablesettings.aspx
    This has an execution timeout property and other related settings.

    In my case, I needed to add this in the Upgrade Actions as per the below code

    using (SPSite site = new SPSite(siteURL))
    using (SPWeb web = site.OpenWeb())
    {
          site.WebApplication.ClientCallableSettings.ExecutionTimeout = TimeSpan.FromMinutes(60);
          site.WebApplication.ClientCallableSettings.MaxObjectPaths = 1000;
          site.WebApplication.ClientCallableSettings.MaxResourcesPerRequest = 1000;
          site.WebApplication.ClientCallableSettings.EnableStackTrace = true;
          site.WebApplication.Update();
    }