我使用独立的c#控制台应用程序实现了REST API调用。 API返回JSON,我将其反序列化,然后将其存储在数据库中。现在我想在Azure平台中实现整个逻辑,以便它可以通过传递开始日期和结束日期以及存储位置来调用(它应该运行三个位置)下面是代码:
static void Main()
{
MakeInventoryRequest();
}
static async void MakeInventoryRequest()
{
using (var client = new HttpClient())
{
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "5051fx6yyy124hhfyuscf34f57ce9");
// Request parameters
queryString["query.locationNumbers"] = "4638";
queryString["availableFromDate"] = "2019-01-01";
queryString["availableToDate"] = "2019-03-07";
var uri = "https://api-test.location.cloud/api/v1/inventory?" + queryString;
using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
using (var response = await client.SendAsync(request))
{
var stream = await response.Content.ReadAsStreamAsync();
if (response.IsSuccessStatusCode == true)
{
List<Inventory> l1 = DeserializeJsonFromStream<List<Inventory>>(stream);
InsertInventoryRecords(l1);
}
if (response.IsSuccessStatusCode == false)
{
throw new Exception("Error Response Code: " + response.StatusCode.ToString() + "Content is: " + response.Content.ReadAsStringAsync().Result.ToString());
}
}
}
}
请使用Azure组件建议最佳设计
有了手头的信息,我认为你有多种选择,你需要找出最适合你的选择。您可以使用云服务来托管控制台应用程序(您必须将其更改为辅助角色,Visual Studio将帮助您转换它)。我不确定您期望的负载,但您可以随时增加和减少实例,这些可以部署到不同的地理位置。
我看到你是持久化数据,如果你想这样做,你可以使用许多SQL产品。要调用REST API,您还可以使用azure函数和ADF。
如果您想了解更多详细信息,请随时发表评论。