Configuring xConnect Client API timeouts


How to configure default and per-request timeouts for the xConnect Client API, both in a Sitecore and non-Sitecore context.

You can set a default timeout when you instantiate the xConnect Client API or you can set a timeout for a particular request.

In a non-Sitecore context, default client timeout can be set by passing in a TimeoutHttpClientModifier. In the following example, a timeout modifier is added to the search, collection, and configuration clients before the configuration is initialized:

using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Schema;
using System;
using System.Threading.Tasks;
using Sitecore.XConnect.Client.WebApi;
using Sitecore.Xdb.Common.Web;
using Sitecore.XConnect.Collection.Model;
using System.Collections.Generic;

namespace Symposium.xConnect.Course
    public class Program
        private static void Main(string[] args)

        private static async Task MainAsync(string[] args)
            CertificateWebRequestHandlerModifierOptions options =

            var certificateModifier = new CertificateWebRequestHandlerModifier(options);

            List<IHttpClientModifier> clientModifiers = new List<IHttpClientModifier>();
            var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(200));

            var collectionClient = new CollectionWebApiClient(new Uri("https://sc900rev170622_xconnect/odata"), clientModifiers, new[] { certificateModifier });
            var searchClient = new SearchWebApiClient(new Uri("https://sc900rev170622_xconnect/odata"), clientModifiers, new[] { certificateModifier });
            var configurationClient = new ConfigurationWebApiClient(new Uri("https://sc900rev170622_xconnect/configuration"), clientModifiers, new[] { certificateModifier });

            var cfg = new XConnectClientConfiguration(
                new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);

                await cfg.InitializeAsync();

            catch (XdbModelConflictException ce)
                Console.WriteLine("ERROR:" + ce.Message);

            using (var client = new XConnectClient(cfg))


If you do not specify a client timeout, the default client timeout is 100 seconds.

There is no default client timeout for the xConnect Client API in a Sitecore context. This is because different features within the platform have different timeout requirements. For example, the tracker must time out quickly if a contact is not available whereas the List Manager must allow time for large batches to be processed.

You can specify a timeout per request by passing in a cancellation token. All extension methods on the client have an overload that accepts a cancellation token:

// GET
var cancellationTokenSource = new CancellationTokenSource(200);
Task<Contact> contactTask = client.GetAsync<Contact>(reference, new ContactExpandOptions() { }, cancellationTokenSource.Token);

var cancellationTokenSource1 = new CancellationTokenSource(200);
await client.SubmitAsync(cancellationTokenSource1.Token);

var results = await client.Contacts.Where(f => f.IsKnown == true).GetBatchEnumerator(10, cancellationTokenSource.Token);

var results = await client.Contacts.Where(f => f.IsKnown == true).ToSearchResults(cancellationTokenSource.Token);


If you are using the synchronous extension methods, you can pass in a TimeSpan.