Sample code for 30+ languages & platforms
.NET Core C# Requires Chilkat v11.6.0+

Azure Table: Retry a Read with Bounded Backoff

See more Azure Table Service Examples

Retries only this GET for selected transient HTTP statuses, at most five attempts. Uses exponential backoff plus jitter and honors numeric or HTTP-date Retry-After without shortening a requested wait. Stops when the server asks for more than 30 seconds, on invalid Retry-After, authentication failures or transport errors. Each connection/read also has a timeout. This is not a generic write-retry policy; uncertain mutation outcomes require reconciliation.

Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.

HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.

Microsoft reference.

Chilkat .NET Core C# Downloads

.NET Core C#
bool success = false;

//  StringBuilder compares text by value in every generated language.
Chilkat.StringBuilder textCompare = new Chilkat.StringBuilder();
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
Chilkat.JsonObject config = new Chilkat.JsonObject();
config.Strict = true;
success = config.LoadFile("qa_data/azure/storage.json");
if (success != true) {
    Debug.WriteLine("Could not load private Azure configuration.");
    return;
}

textCompare.Clear();
textCompare.SetString(config.StringOf("account"));
bool sameText1 = textCompare.ContentsEqual("",true);
if ((config.JsonTypeOf("account") != 1) || (sameText1 == true)) {
    Debug.WriteLine("Supply the storage account name.");
    return;
}

//  access_key is the base64 account key, not a connection string or SAS.
textCompare.Clear();
textCompare.SetString(config.StringOf("access_key"));
bool sameText2 = textCompare.ContentsEqual("",true);
if ((config.JsonTypeOf("access_key") != 1) || (sameText2 == true)) {
    Debug.WriteLine("Supply the base64 account access key.");
    return;
}

Chilkat.StringBuilder accountText = new Chilkat.StringBuilder();
success = accountText.Append(config.StringOf("account"));
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

if ((accountText.Length < 3) || (accountText.Length > 24)) {
    Debug.WriteLine("Storage account names need 3-24 lowercase letters or digits.");
    return;
}

Chilkat.StringBuilder allowedAccountChars = new Chilkat.StringBuilder();
success = allowedAccountChars.Append("abcdefghijklmnopqrstuvwxyz0123456789");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

int charIndex = 0;
while ((charIndex < accountText.Length)) {
    if (allowedAccountChars.Contains(accountText.GetRange(charIndex,1,false),true) != true) {
        Debug.WriteLine("Storage account names need lowercase letters or digits.");
        return;
    }

    charIndex = charIndex + 1;
}

Chilkat.StringBuilder endpoint = new Chilkat.StringBuilder();
success = endpoint.Append(config.StringOf("account"));
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = endpoint.Append(".table.core.windows.net");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

//  Table names contain only letters and digits and are case-insensitive.
//  Entity PartitionKey and RowKey values are case-sensitive.
string resourcePath = "/ExampleCustomers()";
Chilkat.Rest rest = new Chilkat.Rest();
rest.ConnectTimeoutMs = 20000;
rest.IdleTimeoutMs = 60000;
Chilkat.AuthAzureStorage azAuth = new Chilkat.AuthAzureStorage();
azAuth.Account = config.StringOf("account");
azAuth.AccessKey = config.StringOf("access_key");
azAuth.Service = "Table";
azAuth.Scheme = "SharedKey";
azAuth.XMsVersion = "2026-04-06";
success = rest.SetAuthAzureStorage(azAuth);
if (success != true) {
    Debug.WriteLine("Could not configure Shared Key signing.");
    return;
}

Chilkat.Socket connection = new Chilkat.Socket();
connection.RequireSslCertVerify = true;
connection.MaxReadIdleMs = 60000;
connection.MaxSendIdleMs = 60000;
success = connection.Connect(endpoint.GetAsString(),443,true,20000);
if (success != true) {
    Debug.WriteLine("TLS connection failed; inspect diagnostics privately.");
    return;
}

//  Do not replay a write automatically after losing its response.
success = rest.UseConnection(connection,false);
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

string responseText = "";
Chilkat.JsonObject result = new Chilkat.JsonObject();
result.Strict = true;
success = rest.AddHeader("DataServiceVersion","3.0;NetFx");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = rest.AddHeader("MaxDataServiceVersion","3.0;NetFx");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = rest.AddHeader("Content-Type","application/json");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = rest.AddHeader("Accept","application/json;odata=minimalmetadata");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

string partitionKey = "customers-west";
string rowKey = "customer-001";
Chilkat.StringBuilder encodedPk = new Chilkat.StringBuilder();
success = encodedPk.Append(partitionKey);
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

int escapedencodedPk = encodedPk.Replace("'","''");
success = encodedPk.Encode("url_rfc3986","utf-8");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

Chilkat.StringBuilder encodedRk = new Chilkat.StringBuilder();
success = encodedRk.Append(rowKey);
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

int escapedencodedRk = encodedRk.Replace("'","''");
success = encodedRk.Encode("url_rfc3986","utf-8");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

//  Escape apostrophes for OData first, then percent-encode each key once.
Chilkat.StringBuilder entityPath = new Chilkat.StringBuilder();
success = entityPath.Append("/ExampleCustomers(PartitionKey='");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = entityPath.Append(encodedPk.GetAsString());
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = entityPath.Append("',RowKey='");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = entityPath.Append(encodedRk.GetAsString());
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

success = entityPath.Append("')");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

resourcePath = entityPath.GetAsString();
int attempt = 0;
int baseDelayMs = 1000;
bool finished = false;
Chilkat.Http timer = new Chilkat.Http();
Chilkat.Prng jitter = new Chilkat.Prng();
Chilkat.StringBuilder retryText = new Chilkat.StringBuilder();
Chilkat.StringBuilder digits = new Chilkat.StringBuilder();
success = digits.Append("0123456789");
if (success != true) {
    Debug.WriteLine("Could not prepare the request.");
    return;
}

Chilkat.CkDateTime retryDate = new Chilkat.CkDateTime();
Chilkat.CkDateTime currentTime = new Chilkat.CkDateTime();
while ((finished != true)) {
    attempt = attempt + 1;
    responseText = rest.FullRequestNoBody("GET",resourcePath);
    if (rest.LastMethodSuccess != true) {
        Debug.WriteLine("Transport failure; this example does not retry incomplete reads.");
        return;
    }

    int httpStatus = rest.ResponseStatusCode;
    if (httpStatus == 200) {
        finished = true;
    }
    else {
        if ((httpStatus != 408) && (httpStatus != 429) && (httpStatus != 500) && (httpStatus != 502) && (httpStatus != 503) && (httpStatus != 504)) {
            Debug.WriteLine("Non-retryable HTTP status; inspect request ID privately.");
            return;
        }

        if (attempt >= 5) {
            Debug.WriteLine("Retry limit reached.");
            return;
        }

        int delayMs = baseDelayMs + jitter.RandomInt(0,250);
        if (jitter.LastMethodSuccess != true) {
            Debug.WriteLine("Could not generate retry jitter.");
            return;
        }

        success = retryText.SetString(rest.ResponseHdrByName("Retry-After"));
        if (success != true) {
            Debug.WriteLine("Could not prepare the request.");
            return;
        }

        success = retryText.Trim();
        if (success != true) {
            Debug.WriteLine("Could not prepare the request.");
            return;
        }

        if (retryText.Length > 0) {
            bool numericDelay = true;
            int digitIndex = 0;
            while ((digitIndex < retryText.Length)) {
                if (digits.Contains(retryText.GetRange(digitIndex,1,false),true) != true) {
                    numericDelay = false;
                }

                digitIndex = digitIndex + 1;
            }

            int requestedSeconds = 0;
            if (numericDelay == true) {
                if (retryText.Length > 2) {
                    Debug.WriteLine("Retry-After exceeds this example wait budget.");
                    return;
                }

                requestedSeconds = retryText.IntValue;
            }
            else {
                success = retryDate.SetFromRfc822(retryText.GetAsString());
                if (success != true) {
                    Debug.WriteLine("Invalid Retry-After date.");
                    return;
                }

                success = currentTime.SetFromCurrentSystemTime();
                if (success != true) {
                    Debug.WriteLine("Could not prepare the request.");
                    return;
                }

                requestedSeconds = retryDate.DiffSeconds(currentTime) + 1;
            }

            if (requestedSeconds > 30) {
                Debug.WriteLine("Server requested a longer wait; stop instead of retrying too soon.");
                return;
            }

            if (requestedSeconds < 0) {
                requestedSeconds = 0;
            }

            if (requestedSeconds * 1000 > delayMs) {
                delayMs = requestedSeconds * 1000;
            }

        }

        //  Retry only this GET; never copy this loop blindly to mutation requests.
        timer.SleepMs(delayMs);
        baseDelayMs = baseDelayMs * 2;
        rest.Disconnect(10);
        success = connection.Connect(endpoint.GetAsString(),443,true,20000);
        if (success != true) {
            Debug.WriteLine("TLS reconnection failed.");
            return;
        }

        success = rest.UseConnection(connection,false);
        if (success != true) {
            Debug.WriteLine("Could not prepare the request.");
            return;
        }

    }

}

success = result.Load(responseText);
if (success != true) {
    Debug.WriteLine("Expected well-formed JSON.");
    return;
}

textCompare.Clear();
textCompare.SetString(result.StringOf("PartitionKey"));
bool sameText3 = textCompare.ContentsEqual("",true);
if ((result.JsonTypeOf("PartitionKey") != 1) || (sameText3 == true)) {
    Debug.WriteLine("Missing string PartitionKey.");
    return;
}

textCompare.Clear();
textCompare.SetString(result.StringOf("RowKey"));
bool sameText4 = textCompare.ContentsEqual("",true);
if ((result.JsonTypeOf("RowKey") != 1) || (sameText4 == true)) {
    Debug.WriteLine("Missing string RowKey.");
    return;
}

textCompare.Clear();
textCompare.SetString(result.StringOf("PartitionKey"));
bool sameText5 = textCompare.ContentsEqual(partitionKey,true);
textCompare.Clear();
textCompare.SetString(result.StringOf("RowKey"));
bool sameText6 = textCompare.ContentsEqual(rowKey,true);
if ((sameText5 != true) || (sameText6 != true)) {
    Debug.WriteLine("Returned entity keys do not match.");
    return;
}

Debug.WriteLine("Entity read completed with bounded retries.");