【问题标题】:C# to pause, turn on ssas server, backup cube.... how to?C#暂停,打开ssas服务器,备份多维数据集....如何?
【发布时间】:2019-08-17 09:10:19
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# azure-functions ssas-tabular azure-analysis-services azure-function-app


    【解决方案1】:

    ResumeAzureAS()方法here

    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 调用(例如挂起)记录在 here

    【讨论】:

    • 您好,感谢您的回答。我采用了与您描述的相同的方法,但收到“禁止”错误。我怀疑问题来自令牌的生成。我会检查问题可能来自哪里。谢谢你的提示。我会及时通知你进度
    • @MiguelMartinPerez 无论您使用什么身份都需要在 Azure 门户中的 Azure AS 服务器的访问控制 (IAM) 选项卡中提供权限。随意分享您的令牌生成代码。
    • 首先,感谢您的帮助和快速解答。我已经做了一些测试,但无法暂停或恢复;我有一个 403 错误。 pauseresume 和 refresh 的令牌生成是否需要不同?
    • @MiguelMartinPerez 是的。它与刷新不同。当您发布令牌生成代码时,我们可以查看它。
    • 你好,经过几次挫折,因为我很确定我的代码没问题……我找到了根本原因;观众完全错了。正确的受众是 Audience = "management.core.windows.net";
    【解决方案2】:
    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();
    

    【讨论】:

      【解决方案3】:

      正确的受众是:

      audience = "https://management.core.windows.net/";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多