1

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.

Joseph Caruana
  • 2,241
  • 3
  • 31
  • 48

2 Answers2

1

Have you tried

  • keeping default KeepAlive (true),
  • disabling Timeout and
  • keeping default MaxServicePointIdleTime value (which is 100 seconds by default but you set to 2).

Just as:

public static void SetInfiniteTimeout(this ClientContext ctx)
{
    ctx.RequestTimeout = -1;  //ctx.RequestTimeout or System.Threading.Timeout.Infinite;
}

Also, how many seconds it takes for you to get timeout error, in your current configuration?

  • Hi - thank you for your kind reply. Yes, I had tried all the timeout settings. It was timing out after 1.5 mins. In the end, the problem was solved by using client callable settings. Thanks again. +1 for the input. – Joseph Caruana Aug 11 '12 at 05:28
0

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();
}
Joseph Caruana
  • 2,241
  • 3
  • 31
  • 48
  • 1
    OK, but how do you get the SPWebApplication ? – Vroomfundel Sep 30 '13 at 14:41
  • The best solution is to use Server Object Modeal instead of Client Object Model .With Server Object Model you won't face these problems and won't need to tweak/change SP settings and you'll avoid a lot of headache. – Zakos May 06 '15 at 08:05
  • @JosephCaruana Can you post your solution, what exactly did you do with ClientCallable settings? The link that you have in the answer just has the declaration of the property – Katana Sep 12 '18 at 21:19
  • @JosephCaruana could you give a snippet for how you used clientcallablesettings ExecutionTimeout ? – Ahmed Hussein Dec 23 '21 at 20:54
  • @AhmedHussein, I have updated my answer to include a code sample - hope it helps. – Joseph Caruana Dec 24 '21 at 05:21