Starts in:
2 DAYS
3 HRS
42 MIN
25 SEC
Starts in:
2 D
3 H
42 M
25 S
Open Closed

Integration Services #7777


User avatar
0
AbpRaven created

hi everyone. I have microservises template. and I am trying to implement commutication between servises vie Integration Services. Do you have same sample how to implement it? In documentation (https://abp.io/docs/latest/solution-templates/microservice/http-api-calls) i can see that on client side we have to use HttpClient. Does it mean we have to use this one (https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-8.0) or something from ABP?

Thank you in advance.


29 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    You can also use the Static or Dynamic C# clients to call the HTTP APIs of other microservices. However, the Integration Services is the recommended way to communicate between microservices because it allows you to hide your endpoints from the outside world and manage your services more easily.

    Hi,

    I recommend you use the static csharp proxy.

    https://abp.io/docs/latest/solution-templates/microservice/http-api-calls https://abp.io/docs/latest/framework/api-development/static-csharp-clients

  • User Avatar
    0
    AbpRaven created

    And am I right that in current microservice template we have to create projects manualy (for example Domain, Domain.Shared and so on)? Or maybe ABP has some command vie CLI?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    HI,

    we have to create projects manualy (for example Domain, Domain.Shared and so on)

    you don't need to do this.

    you can configure csharp proxy in the Web project

    [DependsOn(
        ......
        typeof(XXXServiceContractsModule), //Service Contracts module
        typeof(AbpVirtualFileSystemModule) //virtual file system
        .....
    )]
    public class XXXWebModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            // Prepare for static client proxy generation
            context.Services.AddStaticHttpClientProxies(
                typeof(XXXServiceContractsModule).Assembly,
                XXXServiceRemoteServiceConsts.RemoteServiceName // add XXXServiceRemoteServiceConsts class to Contracts project
            );
    
            // Include the generated app-generate-proxy.json in the virtual file system
            Configure<AbpVirtualFileSystemOptions>(options =>
            {
                options.FileSets.AddEmbedded<XXXWebModule>();
            });
        }
    }
    

    Add generate-proxy.json config to csproj file

      <ItemGroup>
        <EmbeddedResource Include="**\*generate-proxy.json" />
        <Content Remove="**\*generate-proxy.json" />
      </ItemGroup>
    

    Then you can use abp command to generate proxy

  • User Avatar
    0
    AbpRaven created

    but currently I have this structure

    And I want to split it for a sevrel layers

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    And I want to split it for a sevrel layers

    if you want , you can add them manually.

    But the current layering is simpler

  • User Avatar
    0
    AbpRaven created

    Thank you so much!

  • User Avatar
    0
    AbpRaven created

    HI,

    we have to create projects manualy (for example Domain, Domain.Shared and so on)

    you don't need to do this.

    you can configure csharp proxy in the Web project

    [DependsOn( 
        ...... 
        typeof(XXXServiceContractsModule), //Service Contracts module 
        typeof(AbpVirtualFileSystemModule) //virtual file system 
        ..... 
    )] 
    public class XXXWebModule : AbpModule 
    { 
        public override void ConfigureServices(ServiceConfigurationContext context) 
        { 
            // Prepare for static client proxy generation 
            context.Services.AddStaticHttpClientProxies( 
                typeof(XXXServiceContractsModule).Assembly, 
                XXXServiceRemoteServiceConsts.RemoteServiceName // add XXXServiceRemoteServiceConsts class to Contracts project 
            ); 
     
            // Include the generated app-generate-proxy.json in the virtual file system 
            Configure<AbpVirtualFileSystemOptions>(options => 
            { 
                options.FileSets.AddEmbedded<XXXWebModule>(); 
            }); 
        } 
    } 
    

    Add generate-proxy.json config to csproj file

      <ItemGroup> 
        <EmbeddedResource Include="**\*generate-proxy.json" /> 
        <Content Remove="**\*generate-proxy.json" /> 
      </ItemGroup> 
    

    Then you can use abp command to generate proxy

    I did it in service B and then I ran Service A and tryed to use this command (abp generate-proxy -t csharp -u http://localhost:44331/) in serice B but I get this error System.IO.DirectoryNotFoundException: Could not find a part of the path 'path\Service B\ClientProxies\app-generate-proxy.json'.

  • User Avatar
    0
    AbpRaven created

    ok. I have fixed this problem. Need to manuly create "ClientProxies" folder. But I faced a new one problem. When I use this command abp generate-proxy -t csharp -u http://localhost:44331/ I can not see that Dtos were created. Why? In app-generate-proxy.json I can see them, but not physically.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    The web project should reference to the Service.Contracts project. so, don't need to generate Dtos

  • User Avatar
    0
    AbpRaven created

    I do not have web project. I have only Service and Service.Contract on server side. and only Service on the client side (auth service)

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    OH, i see, in this way, I recommend you to create a new project named HttpApi.Client.

    and configure static proxy in the HttpApi.Client project

  • User Avatar
    0
    AbpRaven created

    It shoud be on the client side (in my case in the auth service)?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    should put it in the service solution

    MyService MyService.HttpApi.Client MyService.Contracts

  • User Avatar
    0
    AbpRaven created

    I see it but in which solution?? I have 2 solutions: auth service (client) and Identity (server). In which one I have to add HttpApi.Client

    Auth Solution (has just 1 project):

    • Service (here I added AbpHttpClient and EmbeddedResource)

    Identoty Solution (has 2 projects):

    • Service
    • Contracts

    So as far as I understood I have to add HttpApi.Client project into Auth Solution. Am I right?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Create HttpApi.Client project for each service.

    [DependsOn(
        typeof(AbpHttpClientModule), //used to create client proxies
        typeof(AbpVirtualFileSystemModule) //virtual file system
    )]
    public class XXXServiceHttpClientModule : AbpModule 
    { 
        public override void ConfigureServices(ServiceConfigurationContext context) 
        { 
            // Prepare for static client proxy generation 
            context.Services.AddStaticHttpClientProxies( 
                typeof(XXXServiceHttpClientModule).Assembly, 
                XXXServiceRemoteServiceConsts.RemoteServiceName
            ); 
     
            // Include the generated app-generate-proxy.json in the virtual file system 
            Configure<AbpVirtualFileSystemOptions>(options => 
            { 
                options.FileSets.AddEmbedded<XXXServiceHttpClientModule>(); 
            }); 
        } 
    } 
    

    then generate proxy file(Dtos, services etc...)

    For example: abp generate-proxy -t csharp -u xxx -m identity (XXXServiceRemoteServiceConsts.RemoteServiceName's value)

    Other services can then reference this project for API calls

  • User Avatar
    0
    AbpRaven created

    Create HttpApi.Client project for each service.

    [DependsOn( 
        typeof(AbpHttpClientModule), //used to create client proxies 
        typeof(AbpVirtualFileSystemModule) //virtual file system 
    )] 
    public class XXXServiceHttpClientModule : AbpModule  
    {  
        public override void ConfigureServices(ServiceConfigurationContext context)  
        {  
            // Prepare for static client proxy generation  
            context.Services.AddStaticHttpClientProxies(  
                typeof(XXXServiceHttpClientModule).Assembly,  
                XXXServiceRemoteServiceConsts.RemoteServiceName 
            );  
      
            // Include the generated app-generate-proxy.json in the virtual file system  
            Configure<AbpVirtualFileSystemOptions>(options =>  
            {  
                options.FileSets.AddEmbedded<XXXServiceHttpClientModule>();  
            });  
        }  
    }  
    

    then generate proxy file(Dtos, services etc...)

    For example: abp generate-proxy -t csharp -u xxx -m identity (XXXServiceRemoteServiceConsts.RemoteServiceName's value)

    Other services can then reference this project for API calls

    it does not help. I have the same result

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    it does not help. I have the same result

    what result?

  • User Avatar
    0
    AbpRaven created

    without dtos

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    can you share the generate-proxy command output log?

  • User Avatar
    0
    AbpRaven created

    yes.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    The CLI expects the DTOs namespace to start with or be consistent with the application service's namespace.

    you can check your dto and service namespace

    For example:

    namespace MyService.Services
    
    ....
    
    namespace MyService.Services.Dtos
    
  • User Avatar
    0
    AbpRaven created

    Does it mean that I have to have DTOs models not in Contracts layer?

  • User Avatar
    0
    AbpRaven created

    Could anyony help me??

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Does it mean that I have to have DTOs models not in Contracts layer?

    no, just the namespace.

  • User Avatar
    0
    AbpRaven created

    Does it mean that I have to have DTOs models not in Contracts layer?

    no, just the namespace.

    And result

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06