Кажется, вы пытаетесь прочитать Azure Table Storage
из HTTP Trigger Function
. Пожалуйста, посмотрите фрагмент кода ниже:
Ваш класс POCO:
public class MyPoco
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string Directory { get; set; }
}
Класс хранения таблицы:
public class TableStorageClass
{
public TableStorageClass()
{
}
public TableStorageClass(DynamicTableEntity entity)
{
PartitionKey = entity.PartitionKey;
RowKey = entity.RowKey;
}
public string PartitionKey { get; set; }
public string RowKey { get; set; }
}
Функция запуска Azure HTTP V2:
public static class FunctionReadFromTableStorage
{
[FunctionName("FunctionReadFromTableStorage")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
//Read Request Body
var content = await new StreamReader(req.Body).ReadToEndAsync();
//Extract Request Body and Parse To Class
MyPoco objMyPoco = JsonConvert.DeserializeObject<MyPoco>(content);
// Validate param because PartitionKey and RowKey is required to read from Table storage In this case , so I am checking here.
dynamic validationMessage;
if (string.IsNullOrEmpty(objMyPoco.PartitionKey))
{
validationMessage = new OkObjectResult("PartitionKey is required!");
return (IActionResult)validationMessage;
}
if (string.IsNullOrEmpty(objMyPoco.RowKey))
{
validationMessage = new OkObjectResult("RowKey is required!");
return (IActionResult)validationMessage;
}
// Table Storage operation with credentials
var client = new CloudTableClient(new Uri("https://YourStorageURL.table.core.windows.net/"),
new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("YourStorageName", "xtaguZokAWbfYG4QDkBjT+YourStorageKey+T/kId/Ng+cl3TfYHtg=="));
var table = client.GetTableReference("YourTableName");
//Query filter
var query = new TableQuery()
{
FilterString = string.Format("PartitionKey eq '{0}' and RowKey eq '{1}'", objMyPoco.PartitionKey, objMyPoco.RowKey)
};
//Request for storage query with query filter
var continuationToken = new TableContinuationToken();
var storageTableQueryResults = new List<TableStorageClass>();
foreach (var entity in table.ExecuteQuerySegmentedAsync(query, continuationToken).GetAwaiter().GetResult().Results)
{
var request = new TableStorageClass(entity);
storageTableQueryResults.Add(request);
}
//As we have to return IAction Type So converting to IAction Class Using OkObjectResult We Even Can Use OkResult
var result = new OkObjectResult(storageTableQueryResults);
return (IActionResult)result;
}
}
Точка для запоминания:
- В случае выполнения
Azure Portal
просто избавьтесь от FunctionReadFromTableStorage
класса
- Вам нужна следующая ссылка для выполнения кода выше
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage.Table;
using System.Collections.Generic;
Шаблон запроса почты:
Образец вызова функции:
{
"PartitionKey": "Your Param According to Table Storage Design" ,
"RowKey": "Your Param According to Table Storage Design",
"Directory": "Your Param According to Table Storage Design"
}
См. Снимок экрана:
![enter image description here](https://i.stack.imgur.com/EJajp.png)
Ответ почтальона:
Ответ зависит от моего собственного дизайна таблицы
[
{
"partitionKey": "Microsoft SharePoint Server",
"rowKey": "2016"
}
]
См. Снимок экрана ниже:
![enter image description here](https://i.stack.imgur.com/BCo8V.png)
Примечание: Мне нравится писать код в простой и удобочитаемой форме. Я только что попробовал это для твоего случая. Если это решит вашу проблему, мои усилия будут
Успех тогда. Это самый простой способ, насколько я знаю, читать из
azure table storage
.
Если у вас все еще есть вопросы, не стесняйтесь поделиться. Спасибо и счастливого кодирования!