Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.6.0+

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.

Microsoft reference.

Chilkat Objective-C Downloads

Objective-C
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoRest.h>
#import <CkoAuthAzureStorage.h>
#import <CkoSocket.h>
#import <CkoXml.h>

BOOL success = NO;

//  StringBuilder compares text by value in every generated language.
CkoStringBuilder *textCompare = [[CkoStringBuilder alloc] init];
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
success = NO;
CkoJsonObject *config = [[CkoJsonObject alloc] init];
config.Strict = YES;
success = [config LoadFile: @"qa_data/azure/storage.json"];
if (success != YES) {
    NSLog(@"%@",@"Could not load private Azure configuration.");
    return;
}

[textCompare Clear];
[textCompare SetString: [config StringOf: @"account"]];
BOOL sameText1 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"account"] intValue] != 1) || (sameText1 == YES)) {
    NSLog(@"%@",@"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: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"access_key"] intValue] != 1) || (sameText2 == YES)) {
    NSLog(@"%@",@"Supply the base64 account access key.");
    return;
}

CkoStringBuilder *accountText = [[CkoStringBuilder alloc] init];
success = [accountText Append: [config StringOf: @"account"]];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

if (([accountText.Length intValue] < 3) || ([accountText.Length intValue] > 24)) {
    NSLog(@"%@",@"Storage account names need 3-24 lowercase letters or digits.");
    return;
}

CkoStringBuilder *allowedAccountChars = [[CkoStringBuilder alloc] init];
success = [allowedAccountChars Append: @"abcdefghijklmnopqrstuvwxyz0123456789"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

int charIndex = 0;
while ((charIndex < [accountText.Length intValue])) {
    if ([allowedAccountChars Contains: [accountText GetRange: [NSNumber numberWithInt: charIndex] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
        NSLog(@"%@",@"Storage account names need lowercase letters or digits.");
        return;
    }

    charIndex = charIndex + 1;
}

CkoStringBuilder *endpoint = [[CkoStringBuilder alloc] init];
success = [endpoint Append: [config StringOf: @"account"]];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

success = [endpoint Append: @".table.core.windows.net"];
if (success != YES) {
    NSLog(@"%@",@"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.
NSString *resourcePath = @"/";
CkoRest *rest = [[CkoRest alloc] init];
rest.ConnectTimeoutMs = [NSNumber numberWithInt:20000];
rest.IdleTimeoutMs = [NSNumber numberWithInt:60000];
CkoAuthAzureStorage *azAuth = [[CkoAuthAzureStorage alloc] init];
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 != YES) {
    NSLog(@"%@",@"Could not configure Shared Key signing.");
    return;
}

CkoSocket *connection = [[CkoSocket alloc] init];
connection.RequireSslCertVerify = YES;
connection.MaxReadIdleMs = [NSNumber numberWithInt:60000];
connection.MaxSendIdleMs = [NSNumber numberWithInt:60000];
success = [connection Connect: [endpoint GetAsString] port: [NSNumber numberWithInt: 443] ssl: YES maxWaitMs: [NSNumber numberWithInt: 20000]];
if (success != YES) {
    NSLog(@"%@",@"TLS connection failed; inspect diagnostics privately.");
    return;
}

//  Do not replay a write automatically after losing its response.
success = [rest UseConnection: connection autoReconnect: NO];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

NSString *responseText = 0;
CkoJsonObject *result = [[CkoJsonObject alloc] init];
result.Strict = YES;
success = [rest AddHeader: @"DataServiceVersion" value: @"3.0;NetFx"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

success = [rest AddHeader: @"MaxDataServiceVersion" value: @"3.0;NetFx"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

success = [rest AddHeader: @"Content-Type" value: @"application/xml"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

success = [rest AddHeader: @"Accept" value: @"application/xml"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

success = [rest AddQueryParam: @"restype" value: @"service"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

success = [rest AddQueryParam: @"comp" value: @"properties"];
if (success != YES) {
    NSLog(@"%@",@"Could not prepare the request.");
    return;
}

responseText = [rest FullRequestNoBody: @"GET" uriPath: resourcePath];
if (rest.LastMethodSuccess != YES) {
    NSLog(@"%@",@"Request did not complete; inspect the target before retrying a write.");
    return;
}

if ([rest.ResponseStatusCode intValue] != 200) {
    NSLog(@"%@%d",@"HTTP status: ",[rest.ResponseStatusCode intValue]);
    NSLog(@"%@%@",@"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;
}

CkoXml *properties = [[CkoXml alloc] init];
properties.Strict = YES;
success = [properties LoadXml: responseText];
if (success != YES) {
    NSLog(@"%@",@"Invalid service-properties XML.");
    return;
}

[textCompare Clear];
[textCompare SetString: properties.Tag];
BOOL sameText3 = [textCompare ContentsEqual: @"StorageServiceProperties" caseSensitive: YES];
if (sameText3 != YES) {
    NSLog(@"%@",@"Unexpected properties root.");
    return;
}

int corsRuleCount = 0;
success = [properties FindChild2: @"Cors"];
if (success == YES) {
    corsRuleCount = [[properties NumChildrenHavingTag: @"CorsRule"] intValue];
}

NSLog(@"%@%d",@"CORS rule count: ",corsRuleCount);
//  Read-only by default. Enabling this replaces the entire CORS rule collection.
BOOL updateCors = NO;
if (updateCors == YES) {
    CkoXml *update = [[CkoXml alloc] init];
    update.Tag = @"StorageServiceProperties";
    [update UpdateChildContent: @"Cors|CorsRule|AllowedOrigins" value: @"https://app.example.com"];
    [update UpdateChildContent: @"Cors|CorsRule|AllowedMethods" value: @"GET"];
    [update UpdateChildContent: @"Cors|CorsRule|AllowedHeaders" value: @"authorization,x-ms-*,dataserviceversion,maxdataserviceversion,accept,content-type"];
    [update UpdateChildContent: @"Cors|CorsRule|ExposedHeaders" value: @"ETag,x-ms-request-id,x-ms-continuation-*"];
    [update UpdateChildContent: @"Cors|CorsRule|MaxAgeInSeconds" value: @"300"];
    [rest Disconnect: [NSNumber numberWithInt: 10]];
    success = [connection Connect: [endpoint GetAsString] port: [NSNumber numberWithInt: 443] ssl: YES maxWaitMs: [NSNumber numberWithInt: 20000]];
    if (success != YES) {
        NSLog(@"%@",@"TLS reconnection failed.");
        return;
    }

    success = [rest UseConnection: connection autoReconnect: NO];
    if (success != YES) {
        NSLog(@"%@",@"Could not prepare the request.");
        return;
    }

    responseText = [rest FullRequestString: @"PUT" uriPath: resourcePath bodyText: [update GetXml]];
    if (rest.LastMethodSuccess != YES) {
        NSLog(@"%@",@"Request did not complete; inspect the target before retrying a write.");
        return;
    }

    if ([rest.ResponseStatusCode intValue] != 202) {
        NSLog(@"%@%d",@"HTTP status: ",[rest.ResponseStatusCode intValue]);
        NSLog(@"%@%@",@"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;
    }

}

NSLog(@"%@",@"Service properties inspected; optional CORS update completed if enabled.");