Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#.NET中按资源组列出azure工作区_C#_Rest_Azure - Fatal编程技术网

在C#.NET中按资源组列出azure工作区

在C#.NET中按资源组列出azure工作区,c#,rest,azure,C#,Rest,Azure,如何按ressource组获取工作区列表 我发现了这个Rest调用: 要调用的ressource是: GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces?api-version=2018-04-01 在LogAnalyticsRESTAPI文档下,但似乎没有与azur

如何按ressource组获取工作区列表

我发现了这个Rest调用:

要调用的ressource是:

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces?api-version=2018-04-01
在LogAnalyticsRESTAPI文档下,但似乎没有与azure.NETSDK中的此调用等效的调用


我必须使用HttpClient之类的工具从我的C代码中调用Rest,还是有一种更简单的方法来发出查询?

正如你在文章中提到的两个resource
OperationalInsights
Databricks
一样,不清楚你想要使用哪一个,所以我列出了它们

对于
OperationalInsights
,您可以下载以使用SDK

而对于
Databricks
,我在中也找不到任何SDK。调用RESTAPI是一种标准的方法,AFAIK似乎没有更简单的方法

使用SDK或REST都需要通过注册AD应用程序并为应用程序分配角色来获取必要的信息(appId、secretKey、tenantId)。请跟我来

然后使用下面的代码段。请记住安装以生成凭据

var appId = "ApplicationID";
var secretKey = "SecretKey";
var tenantId = "TenantID(aka DirectoryID)";
var subscriptionId = "SubscriptionId";
var resourceGroupName = "ResourceGroupName";

var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse = context.AcquireTokenAsync("https://management.azure.com/", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;

//OperationalInsights
var opsClient = new OperationalInsightsManagementClient(new TokenCredentials(accessToken))
{
     SubscriptionId = subscriptionId
};
var workspaces = opsClient.Workspaces.ListByResourceGroupAsync(resourceGroupName).Result;


// Databricks
using (var client = new HttpClient())
{
     client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
     client.BaseAddress = new Uri("https://management.azure.com/");

     using (var response = await client.GetAsync(
                $"subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces?api-version=2018-04-01"))
     {
          response.EnsureSuccessStatusCode();
          var content = await response.Content.ReadAsStringAsync();
          JObject json = JObject.Parse(content);
          Console.WriteLine(json);
     }
}

正如您在帖子中提到的两个资源
OperationalInsights
Databricks
,不清楚您要使用哪一个,所以我列出了这两个资源

对于
OperationalInsights
,您可以下载以使用SDK

而对于
Databricks
,我在中也找不到任何SDK。调用RESTAPI是一种标准的方法,AFAIK似乎没有更简单的方法

使用SDK或REST都需要通过注册AD应用程序并为应用程序分配角色来获取必要的信息(appId、secretKey、tenantId)。请跟我来

然后使用下面的代码段。请记住安装以生成凭据

var appId = "ApplicationID";
var secretKey = "SecretKey";
var tenantId = "TenantID(aka DirectoryID)";
var subscriptionId = "SubscriptionId";
var resourceGroupName = "ResourceGroupName";

var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse = context.AcquireTokenAsync("https://management.azure.com/", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;

//OperationalInsights
var opsClient = new OperationalInsightsManagementClient(new TokenCredentials(accessToken))
{
     SubscriptionId = subscriptionId
};
var workspaces = opsClient.Workspaces.ListByResourceGroupAsync(resourceGroupName).Result;


// Databricks
using (var client = new HttpClient())
{
     client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
     client.BaseAddress = new Uri("https://management.azure.com/");

     using (var response = await client.GetAsync(
                $"subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Databricks/workspaces?api-version=2018-04-01"))
     {
          response.EnsureSuccessStatusCode();
          var content = await response.Content.ReadAsStringAsync();
          JObject json = JObject.Parse(content);
          Console.WriteLine(json);
     }
}

嗨,杰瑞,谢谢你的回答,你救了我一天。我在寻找你答案的第一部分,请问你有没有熟悉OperationalInsights nugget包类型的ressource?@ZackISSER只得到了,关于此资源的描述似乎很少。嗨,jerry,有没有使用OperationalInsightsManagementClient类编写跨工作区查询?一天前我发布了这个问题:@ZackISSER,很抱歉我迟迟没有回复,也谢谢你邀请我提供建议,我已经添加了我的解决方案。嗨,Jerry,谢谢你的回答,你救了我一天。我在寻找你答案的第一部分,请问你有没有熟悉OperationalInsights nugget包类型的ressource?@ZackISSER只得到了,关于此资源的描述似乎很少。嗨,jerry,有没有使用OperationalInsightsManagementClient类编写跨工作区查询?一天前我发布了这个问题:@ZackISSER,很抱歉我的回复被耽搁了很久,也感谢你邀请我提供建议,我已经添加了我的解决方案。