Azure Cosmos DB interaction works from WinForms, but fail from Azure Cloud Service in C#

44 views Asked by At

When I interact with CosmosDB from Azure Cloud Service I am getting 'Forbidden' on each call that deals with data in the table. Even creating a table is 'Forbidden' from inside the service. The same code works perfectly from the WinForms application.

Here is the code I am using on my desktop WinForms app (works perfectly) and fails with 'Forbidden' inside Cloud Service even if I run it through VS Debugger on my machine:

using Microsoft.Azure.Cosmos.Table;
...
string connectionString = "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=yyy;TableEndpoint=https://xxx.table.cosmos.azure.com:443/;";

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

TableClientConfiguration config = new TableClientConfiguration();
config.UseRestExecutorForCosmosEndpoint = true;

CloudTableClient tableClient = storageAccount.CreateCloudTableClient(config);

// Create the table if it doesn't exist
CloudTable tbl1 = tableClient.GetTableReference("table1");
tbl1.CreateIfNotExists();

CloudTable tbl2 = tableClient.GetTableReference("table2");
tbl2.CreateIfNotExists();

Running on Azure inside the service, 'CreateIfNotExists' call will fail with 'Forbidden'. Is there something I have to specify on the database/table itself or am I doing something wrong?

Thanks

1

There are 1 answers

0
Kajko On

I got it working. You can access CosmosDB only using TLS 1.2.

After I added this line on the Start of the service it started working just fine.

        public void Start()
        {
            System.Net.ServicePointManager.SecurityProtocol = 
                System.Net.SecurityProtocolType.Ssl3 |
                System.Net.SecurityProtocolType.Tls |
                System.Net.SecurityProtocolType.Tls11 |
                System.Net.SecurityProtocolType.Tls12;

Sorry for the confusion.