[英]Data From REST API In Azure
I have implemented REST API calls using a standalone c# console application. 我已经使用独立的c#控制台应用程序实现了REST API调用。 The API returns JSON which i'm deserializing and then storing it in the database.
该API返回我要反序列化的JSON,然后将其存储在数据库中。 Now i want to implement the entire logic in Azure platform so that it can invoked by passing start date and an end date and store location (it should run for three location) Below is the code:
现在,我想在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());
}
}
}
}
Please suggest the best possible design using Azure components 请提出使用Azure组件的最佳设计建议
With the information in hand I think you have multiple options , you need to find out which works for you the best . 掌握了这些信息后,我认为您有多种选择,您需要找出最适合您的方法。 You can use Cloud service to host the console app ( you will have to change it to worker role , Visual studio will help you to convert that ) .
您可以使用Cloud服务托管控制台应用程序(您必须将其更改为辅助角色,Visual Studio将帮助您进行转换)。 I am not sure about the load which you are expecting but you can always increase and decrease the instance and these can be deployed to different geographies .
我不确定您所期望的负载,但是您始终可以增加和减少实例,并且可以将它们部署到不同的地理位置。
I see that you are persisting the data , if you want to do that you can use many of the SQL offerings . 我看到您正在保留数据,如果要这样做,则可以使用许多SQL产品。 For invoking the REST API you can also azure functions and ADF.
对于调用REST API,您还可以对函数和ADF进行处理。
Please feel free to comment if you want any more details on the same. 如果您想要更多有关此内容的详细信息,请随时发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.