Angular 5和.Net Core 2.1-Http请求挂断

时间:2018-10-11 14:57:12

标签: angular asp.net-core-2.1

我在AWS上托管了一个应用程序(Asp.Net Core 2.1后端,Angular 5前端)。为了构建包含用户帐户信息的对象,我提出了许多Http请求来检索有关帐户的信息。但是,很多时候,尝试发出此系列请求时,应用程序都挂断了电话。我尝试了组合请求的不同方法,它们都有相同的问题(失败的频率不同),但是它们都给了我相同的问题。我已经尝试过combineLatestObservable.joinFork和链接订阅。最后一个选项确实很丑陋,但它产生错误的频率似乎比其他两种方法少。

下面是这三种方法的示例,以及两个屏幕截图,显示了请求链在正常工作时或失败时的样子。

我不认为这是过多的请求...但是我显然做错了什么。有什么想法吗?

应该注意的是,在本地发布或在VS中运行应用程序时,我没有这个问题。它仅在发布到云后才发生。我的服务器日志中没有看到任何错误。


最新组合

const filterParams = { accountId: account.id };

return combineLatest(
  this.getAccount(account.id),
  this.adfiService.listAdfis(filterParams),
  this.feedService.listFeeds(filterParams),
  this.feedGroupService.listFeedGroups(filterParams),
  this.feedGroupService.listLivestocks(filterParams),
  this.farmService.listFarms(filterParams),
  this.gatewayService.listGateways(filterParams),
  this.barnService.listBarns(filterParams),
  this.binService.listBins(filterParams),
  this.sensorService.listSensors(filterParams),
  this.definitionService.listDefinitions(filterParams),
  this.userService.listUsers(filterParams)
).map(([res1, res2, res3, res4, res5, res6, res7, res8, res9, res10, res11, res12]) => {
  this.accountObservable = {
    account: res1 as Account,
    adfis: res2 as Adfi[],
    feeds: res3 as Feed[],
    feedGroups: res4 as FeedGroup[],
    livestocks: res5 as Livestock[],
    farms: res6 as Farm[],
    gateways: res7 as Gateway[],
    barns: res8 as Barn[],
    bins: res9 as Bin[],
    sensors: res10 as Sensor[],
    definitions: res11 as Definition[],
    users: res12 as User[]
  } as AccountObservable;
  return this.setVariables(this.accountObservable);
});


Observable.forkJoin

const filterParams = { accountId: account.id };

return Observable.forkJoin(
  this.getAccount(account.id).map(res => res),
  this.adfiService.listAdfis(filterParams).map(res => res),
  this.feedService.listFeeds(filterParams).map(res => res),
  this.feedGroupService.listFeedGroups(filterParams).map(res => res),
  this.feedGroupService.listLivestocks(filterParams).map(res => res),
  this.farmService.listFarms(filterParams).map(res => res),
  this.gatewayService.listGateways(filterParams).map(res => res),
  this.barnService.listBarns(filterParams).map(res => res),
  this.binService.listBins(filterParams).map(res => res),
  this.sensorService.listSensors(filterParams).map(res => res),
  this.definitionService.listDefinitions(filterParams).map(res => res),
  this.userService.listUsers(filterParams).map(res => res)
).map(res => {
  this.Observable.forkJoin = {
    account: res[0] as Account,
    adfis: res[1] as Adfi[],
    feeds: res[2] as Feed[],
    feedGroups: res[3] as FeedGroup[],
    livestocks: res[4] as Livestock[],
    farms: res[5] as Farm[],
    gateways: res[6] as Gateway[],
    barns: res[7] as Barn[],
    bins: res[8] as Bin[],
    sensors: res[9] as Sensor[],
    definitions: res[10] as Definition[],
    users: res[11] as User[]
  } as AccountObservable;
  return this.setVariables(this.accountObservable);
});


连锁订阅

const filterParams = { accountId: this.selectedAccount.id };

return this.getAccount(this.selectedAccount.id).map(
  (res: Account) => {
    this.selectedAccount = res;
    this.accountObservable.account = res;
    this.adfiService.listAdfis(filterParams).subscribe(
      (res: Adfi[]) => { this.accountObservable.adfis = res },
      () => {},
      () => {
        this.accountLoadingStatus.emit("adfis (5%)");
        this.feedGroupService.listLivestocks(filterParams).subscribe(
          (res: Livestock[]) => { this.accountObservable.livestocks = res },
          () => {},
          () => {
            this.accountLoadingStatus.emit("livestocks (10%)");
            this.feedService.listFeeds(filterParams).subscribe(
              (res: Feed[]) => { this.accountObservable.feeds = res },
              () => { },
              () => {
                this.accountLoadingStatus.emit("feeds (20%)");
                this.feedGroupService.listFeedGroups(filterParams).subscribe(
                  (res: FeedGroup[]) => { this.accountObservable.feedGroups = res },
                  () => { },
                  () => {
                    this.accountLoadingStatus.emit("feed groups (30%)");
                    this.farmService.listFarms(filterParams).subscribe(
                      (res: Farm[]) => { this.accountObservable.farms = res },
                      () => { },
                      () => {
                        this.accountLoadingStatus.emit("farms (35%)");
                        this.gatewayService.listGateways(filterParams).subscribe(
                          (res: Gateway[]) => { this.accountObservable.gateways = res },
                          () => { },
                          () => {
                            this.accountLoadingStatus.emit("gateways (40%)");
                            this.barnService.listBarns(filterParams).subscribe(
                              (res: Barn[]) => { this.accountObservable.barns = res },
                              () => { },
                              () => {
                                this.accountLoadingStatus.emit("barns (50%)");
                                this.binService.listBins(filterParams).subscribe(
                                  (res: Bin[]) => { this.accountObservable.bins = res },
                                  () => { },
                                  () => {
                                    this.accountLoadingStatus.emit("bins (60%)");
                                    this.sensorService.listSensors(filterParams).subscribe(
                                      (res: Sensor[]) => { this.accountObservable.sensors = res },
                                      () => { },
                                      () => {
                                        this.accountLoadingStatus.emit("sensors (70%)");
                                        this.definitionService.listDefinitions(filterParams).subscribe(
                                          (res: Definition[]) => { this.accountObservable.definitions = res },
                                          () => { },
                                          () => {
                                            this.accountLoadingStatus.emit("reading types (80%)");
                                            this.userService.listUsers(filterParams).subscribe(
                                              (res: User[]) => { this.accountObservable.users = res },
                                              () => { },
                                              () => {
                                                this.accountLoadingStatus.emit("users (90%)");
                                                return this.setVariables(this.accountObservable);
});});});});});});});});});});});});


成功的请求

enter image description here


请求失败

enter image description here 挂断的电话之后的所有请求都将被取消。

0 个答案:

没有答案