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)
-
0
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
-
0
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?
-
0
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
-
0
-
0
And I want to split it for a sevrel layers
if you want , you can add them manually.
But the current layering is simpler
-
0
Thank you so much!
-
0
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'.
-
0
-
0
Hi,
The web project should reference to the
Service.Contracts
project. so, don't need to generate Dtos -
0
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)
-
0
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 -
0
It shoud be on the client side (in my case in the auth service)?
-
0
Hi,
should put it in the service solution
MyService
MyService.HttpApi.Client
MyService.Contracts
-
0
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?
-
0
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
-
0
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
-
0
it does not help. I have the same result
what result?
-
0
-
0
Hi,
can you share the generate-proxy command output log?
-
0
-
0
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
-
0
Does it mean that I have to have DTOs models not in Contracts layer?
-
0
Could anyony help me??
-
0
Does it mean that I have to have DTOs models not in Contracts layer?
no, just the namespace.
-
0