I am writing a code that will connect to an azure storage table from Azure function.This should return a HTTP response after checking a certain variable in a table rowkey.
There is an error run.csx(2,1): error CS0006: Metadata file 'Microsoft.WindowsAzure.Storage' could not be found
run.csx(8,17): error CS0234: The type or namespace name 'WindowsAzure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
run.csx(27,5): error CS0246: The type or namespace name 'CloudStorageAccount' could not be found (are you missing a using directive or an assembly reference?)
I am not sure how I can install the assembly reference from Azure portal function. I am not using a VS code to code as this is already an existing infrastucture built from Portal.
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string xx= req.Query["xx"];
if (string.IsNullOrEmpty(xx))
{
return new BadRequestObjectResult("Please enter an xx.");
}
string account = "XXW";
string accountKey = "YYW";
string tableName = "TWY";
string connectionString = $"DefaultEndpointsProtocol=https;AccountName={account};AccountKey={accountKey};EndpointSuffix=core.windows.net";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference(tableName);
TableOperation operation = TableOperation.Retrieve(xx, xx);
TableResult result = await table.ExecuteAsync(operation);
string responseMessage = (result.Result != null) ?
$"xx: {xx} exists in the table." :
$"xx: {xx} does not exist in the table.";
return new OkObjectResult(responseMessage);
}