获取对停留在待处理状态的api的请求

时间:2019-12-09 10:33:14

标签: c# angular

对于不好的编辑技能,我事先表示歉意,我是发布问题的新手

我正在尝试从有角度的应用程序中调用我的C#API,但是该请求被挂起。我认为我的打字稿代码中没有错误,但是我是C#的新手,因此可能与api有关,可能是由于异步。

这是api代码

    {
        private static readonly string Tenant = "https://login.microsoftonline.com/{azure.tenant}/";
        private static readonly string Resource = "https://analysis.windows.net/powerbi/api";

        private string getToken()
        {
            var authContext = new AuthenticationContext(Tenant);
            var clientCredential = new ClientCredential(AppId, AppSecret);
            var token = authContext.AcquireTokenAsync(Resource, clientCredential);
            return token.Result.AccessToken;
        }

        private PowerBIClient getPBIClient()
        {
            var token = new TokenCredentials(getToken(), "Bearer");
            return new PowerBIClient(new Uri("https://api.powerbi.com/"), token);
        }

        public async Task<ODataResponseListReport> getReportsAsync(string ws)
        {
            PowerBIClient pbiClient = getPBIClient();

            var reports = await pbiClient.Reports.GetReportsInGroupAsync(ws);
            return reports;
        }

        public async Task<ReportEmbeddingData> getReportEmbeddingDataAsync(string ws, string rep)
        {
            PowerBIClient pbiClient = getPBIClient();

            var report = await pbiClient.Reports.GetReportInGroupAsync(ws, rep);
            var embedUrl = report.EmbedUrl;
            var reportName = report.Name;

            GenerateTokenRequest genTokenReqParam = new GenerateTokenRequest(accessLevel: "view");

            string embedToken = (await pbiClient.Reports.GenerateTokenInGroupAsync(ws, rep, genTokenReqParam)).Token;
            return new ReportEmbeddingData {
                reportId = rep,
                reportName = reportName,
                embedUrl = embedUrl,
                accessToken = embedToken
            };
        }
    }

And here is my angular call that's being done on ngOnInit

getReports(){
    this.http.get("http://localhost:44391/api/Auth?ws="+this.workspaceId)
    .subscribe((response) => {
      this.reportArray = response;
      console.log(this.reportArray);
    });
  }

0 个答案:

没有答案