1

我正在用 C#(通过 REST API)构建一些函数应用程序,以刷新位于 azure ssas 服务器上的表格多维数据集。到目前为止,没有问题。但是,我找不到暂停/启动 ssas 服务器的方法(我在 powershell 中看到了一些文档,但我想留在 C# 中以免混合语言)

有没有人创造过这样的东西?

我试图暂停 POST,但目前没有解决方案。

4

3 回答 3

1

请参阅此处ResumeAzureAS()的方法:

protected async Task<bool> ResumeAzureAS()
        {
            HttpClient client = new HttpClient();
            var apiURI = new Uri(string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.AnalysisServices/servers/{2}/resume?api-version=2016-05-16", subscriptionID, resourcegroup, server));

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            HttpResponseMessage response = await client.PostAsync(apiURI.ToString(), null);
            response.EnsureSuccessStatusCode();
            return true;
        }

其余 API 调用(例如挂起)记录在此处

于 2019-08-18T04:24:11.010 回答
0
private async Task<string> AASAcquireToken()
    {
        // Get auth token and add the access token to the authorization header of the request.
        string authority = "https://login.windows.net/" + tenant + "/oauth/authorize";
        AuthenticationContext ac = new AuthenticationContext(authority);
        ClientCredential cred = new ClientCredential(clientID, keyID);
        AuthenticationResult ar = await ac.AcquireTokenAsync(audience, cred);
        return ar.AccessToken;

    } 

受众设置为“ https://management.azure.com

对于“暂停”本身:我将门户网站 azure 中提到的完整名称用作服务器名称“asazure://northeurope.asazure.windows ....”对于 api 的版本,我不知道在哪里找到它,所以我使用我在网上找到的一个。

        var apiURI = new Uri(string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.AnalysisServices/servers/{2}/suspend?api-version=2016-05-16", subscription, ressourceID, servername));

        audience = "https://management.azure.com";

        myClient.BaseAddress = new Uri(location);
        myClient.DefaultRequestHeaders.Accept.Clear();
        myClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        myClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await AASAcquireToken());

        HttpResponseMessage response = await myClient.PostAsync(apiURI.ToString(), null);
        var output = await response.Content.ReadAsStringAsync();

        response.EnsureSuccessStatusCode();
于 2019-08-27T09:18:28.873 回答
0

正确的观众是:

audience = "https://management.core.windows.net/";
于 2019-08-29T07:47:16.050 回答