Azure Table: Inspect Service Properties and Optionally Set CORS
See more Azure Table Service Examples
GET retrieves Table service properties as XML. Set updateCors=true only after changing the demonstration origin and reviewing existing rules. PUT sends only a complete Cors element, replacing the full CORS rule set while preserving omitted Logging/HourMetrics/MinuteMetrics settings. It expects 202. CORS controls browser access to responses; it does not grant Table authorization, and non-browser clients do not rely on it.
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.
Chilkat C# Downloads
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 = "/";
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/xml");
if (success != true) {
Debug.WriteLine("Could not prepare the request.");
return;
}
success = rest.AddHeader("Accept","application/xml");
if (success != true) {
Debug.WriteLine("Could not prepare the request.");
return;
}
success = rest.AddQueryParam("restype","service");
if (success != true) {
Debug.WriteLine("Could not prepare the request.");
return;
}
success = rest.AddQueryParam("comp","properties");
if (success != true) {
Debug.WriteLine("Could not prepare the request.");
return;
}
responseText = rest.FullRequestNoBody("GET",resourcePath);
if (rest.LastMethodSuccess != true) {
Debug.WriteLine("Request did not complete; inspect the target before retrying a write.");
return;
}
if (rest.ResponseStatusCode != 200) {
Debug.WriteLine("HTTP status: " + Convert.ToString(rest.ResponseStatusCode));
Debug.WriteLine("Request ID: " + rest.ResponseHdrByName("x-ms-request-id"));
// 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
// Keep response bodies private. Reconcile uncertain writes before retrying.
return;
}
Chilkat.Xml properties = new Chilkat.Xml();
properties.Strict = true;
success = properties.LoadXml(responseText);
if (success != true) {
Debug.WriteLine("Invalid service-properties XML.");
return;
}
textCompare.Clear();
textCompare.SetString(properties.Tag);
bool sameText3 = textCompare.ContentsEqual("StorageServiceProperties",true);
if (sameText3 != true) {
Debug.WriteLine("Unexpected properties root.");
return;
}
int corsRuleCount = 0;
success = properties.FindChild2("Cors");
if (success == true) {
corsRuleCount = properties.NumChildrenHavingTag("CorsRule");
}
Debug.WriteLine("CORS rule count: " + Convert.ToString(corsRuleCount));
// Read-only by default. Enabling this replaces the entire CORS rule collection.
bool updateCors = false;
if (updateCors == true) {
Chilkat.Xml update = new Chilkat.Xml();
update.Tag = "StorageServiceProperties";
update.UpdateChildContent("Cors|CorsRule|AllowedOrigins","https://app.example.com");
update.UpdateChildContent("Cors|CorsRule|AllowedMethods","GET");
update.UpdateChildContent("Cors|CorsRule|AllowedHeaders","authorization,x-ms-*,dataserviceversion,maxdataserviceversion,accept,content-type");
update.UpdateChildContent("Cors|CorsRule|ExposedHeaders","ETag,x-ms-request-id,x-ms-continuation-*");
update.UpdateChildContent("Cors|CorsRule|MaxAgeInSeconds","300");
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;
}
responseText = rest.FullRequestString("PUT",resourcePath,update.GetXml());
if (rest.LastMethodSuccess != true) {
Debug.WriteLine("Request did not complete; inspect the target before retrying a write.");
return;
}
if (rest.ResponseStatusCode != 202) {
Debug.WriteLine("HTTP status: " + Convert.ToString(rest.ResponseStatusCode));
Debug.WriteLine("Request ID: " + rest.ResponseHdrByName("x-ms-request-id"));
// 404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
// Keep response bodies private. Reconcile uncertain writes before retrying.
return;
}
}
Debug.WriteLine("Service properties inspected; optional CORS update completed if enabled.");