abp使用动态api客户端注意事项

发布时间 2023-08-03 15:58:29作者: hello_stone

步骤按照官方的来就行

API/Dynamic CSharp API Clients | Documentation Center | ABP.IO

但有一点要注意,这也是官方文档没提及的,比如你在application这一层调用另一个项目的api客户端

则要在application层的module里加上依赖,这个容易忘记。

    [DependsOn(
        typeof(BankHttpApiClientModule),
        typeof(WapHttpApiClientModule),
        typeof(ContractDomainModule),
        typeof(AbpTenantManagementApplicationModule),
        typeof(AbpFeatureManagementApplicationModule),
        typeof(AbpSettingManagementApplicationModule),
        typeof(ContractApplicationContractsModule)
        )]
    public class ContractApplicationModule : AbpModule

 

api之间的调用需要传递access_token的时候,需要在host或web项目里加上一下代码

appsettings.json

"RemoteServices": {
    "Default": {
      "BaseUrl": "http://localhost:7003/",
      "UseCurrentAccessToken": "true"
    },
    "Contracts": {
      "BaseUrl": "http://localhost:7002/",
      "UseCurrentAccessToken": "true"
    },
    "Bank": {
      "BaseUrl": "http://localhost:7003/",
      "UseCurrentAccessToken": "true"
    },
    "CustomerWap": {
      "BaseUrl": "http://localhost:7001/",
      "UseCurrentAccessToken": "true"
    }

同时在项目的module上加上

install-package Volo.Abp.Http.Client.IdentityModel.Web -version 4.4.4

[DependsOn(
        typeof(AbpHttpClientIdentityModelWebModule)
    )]