Open Closed

Synchrounous communication between services #10013


User avatar
0
carl.hallqvist created

I’m trying to call the DocumentService from the InvoiceService and have been following this guide: https://abp.io/docs/latest/guides/synchronous-interservice-communication I suspect that some parts of the guide are either incorrect or outdated — especially the module dependency part referencing typeof(ProductServiceHttpApiClientModule), which I can’t find in our solution. Could it actually refer to ProductServiceContractsModule instead? Anyway, I’m getting an error in the deployment logs in the InvoiceService (seems that DocumentService endpoints are not found?):

[20:29:57 INF] Found 2 events in the inbox.
[20:29:57 ERR] An exception was thrown while activating InvoiceService.TicketCompletedEventHandler -> Castle.Proxies.InvoiceManagerProxy.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating InvoiceService.TicketCompletedEventHandler -> Castle.Proxies.InvoiceManagerProxy.
 ---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'Castle.Proxies.InvoiceManagerProxy' can be invoked with the available services and parameters:
Cannot resolve parameter 'DocumentService.Documents.IDocumentsAppService documentsAppService' of constructor 'Void .ctor(Castle.DynamicProxy.IInterceptor[], InvoiceService.Invoices.IInvoiceRepository, InvoiceService.Resources.IResourceRepository, InvoiceService.Customers.ICustomerRepository, InvoiceService.Invoices.IInvoiceResourceRepository, InvoiceService.PlaceOfPayments.IPlaceOfPaymentRepository, Volo.Abp.EventBus.Distributed.IDistributedEventBus, Volo.Abp.Data.IDataFilter, DocumentService.Documents.IDocumentsAppService, Microsoft.Extensions.Logging.ILogger`1[InvoiceService.Invoices.InvoiceManager])'.

See https://autofac.rtfd.io/help/no-constructors-bindable for more info.
   at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass14_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   --- End of inner exception stack trace ---
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest& request)
   at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest& request)
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Volo.Abp.EventBus.IocEventHandlerFactory.GetHandler()
   at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List`1 exceptions, InboxConfig inboxConfig)
   at Volo.Abp.EventBus.EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData, List`1 exceptions, InboxConfig inboxConfig)
   at Volo.Abp.EventBus.Distributed.DistributedEventBusBase.TriggerHandlersFromInboxAsync(Type eventType, Object eventData, List`1 exceptions, InboxConfig inboxConfig)
   at Volo.Abp.EventBus.RabbitMq.RabbitMqDistributedEventBus.ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig)
   at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
   at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
   at Volo.Abp.EventBus.Distributed.InboxProcessor.TimerOnElapsed(AbpAsyncTimer arg)
   at Volo.Abp.Threading.AbpAsyncTimer.Timer_Elapsed()
[20:29:57 ERR] ---------- Exception Data ----------
ActivatorChain = InvoiceService.TicketCompletedEventHandler -> Castle.Proxies.InvoiceManagerProxy

Do you have any tips or ideas about what might be causing this issue? Best regards


9 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    To enable synchronous communication between services in ABP (such as calling DocumentService from InvoiceService), you must reference the correct modules and configure dependencies as described in the official guide.

    Based on your error, the problem is that the dependency injection system cannot resolve the IDocumentsAppService in your InvoiceManager. This typically means the HttpApi.Client module for DocumentService is not referenced or registered properly in InvoiceService.

    Here is the correct approach, following the official documentation:

    1. Reference the HttpApi.Client Project
      • In your InvoiceService.Application (or equivalent) project, add a reference to the DocumentService.HttpApi.Client project:
    <ProjectReference Include="..\..\..\document\src\DocumentService.HttpApi.Client\DocumentService.HttpApi.Client.csproj" />
    
    1. Add Module Dependency
      • In your InvoiceServiceApplicationModule, add a dependency on the DocumentServiceHttpApiClientModule:
    [DependsOn(
             typeof(DocumentServiceHttpApiClientModule)
         )]
         public class InvoiceServiceApplicationModule : AbpModule
         {
             // ...
         }
    
    • The guide's reference to ProductServiceHttpApiClientModule is just an example. You should use the actual module class from your DocumentService.HttpApi.Client project, which is typically named DocumentServiceHttpApiClientModule.
    1. Configure Remote Service Endpoints
      • In your InvoiceService.HttpApi.Host's appsettings.json, configure the remote service endpoint for DocumentService:
    "RemoteServices": {
           "Default": {
             "BaseUrl": "https://your-document-service-url/"
           }
         }
    
    1. Do Not Use Contracts Module for Remote Calls

      • The Contracts module (DocumentServiceContractsModule) is for sharing DTOs and interfaces, not for enabling remote HTTP calls. You must use the HttpApi.Client module for remote service proxies.
    2. Rebuild and Restart

      • After making these changes, rebuild your solution and restart the services.

    If you follow these steps and ensure the correct module is referenced and registered, the DI system will be able to resolve IDocumentsAppService as a dynamic HTTP proxy, and your error should be resolved.

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    carl.hallqvist created

    I dont have any DocumentService.HttpApi.Client project. Only DocumentService, and since we are using multiple repos (InvoiceService and DocumentService are separated in different Git repos), we would rather not include the DocuemntService code in the InvoiceSerivce repo.

    Best regards,

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Could you share some code to help us understand your case?

    You can use Static C# API Client Proxies between your services.

    https://abp.io/docs/latest/framework/api-development/static-csharp-clients?_redirected=B8ABF606AA1BDF5C629883DF1061649A

    Thanks.

  • User Avatar
    0
    carl.hallqvist created

    With pleasure! In this case, when an event is received, an invoice is generated that should be uploaded to the DocumentService. I’ve included the entire DocumentService.Contracts project in the InvoiceService.

    using DocumentService.Documents;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.EventBus.Distributed;
    using Volo.Abp.Uow;
    
    namespace InvoiceService;
    
    public class InvoiceAttestedAckEventHandler : IDistributedEventHandler<InvoiceAttestedAckEto>, ITransientDependency
    {
        protected InvoiceManager _invoiceManager;
        protected IInvoiceRepository _invoiceRepository;
        protected IDocumentsAppService _documentsAppService;
    
        public InvoiceAttestedAckEventHandler(
            InvoiceManager invoiceManager,
            IInvoiceRepository invoiceRepository,
            IDocumentsAppService documentsAppService
        )
        {
            _invoiceManager = invoiceManager;
            _invoiceRepository = invoiceRepository;
            _documentsAppService = documentsAppService;
        }
        
        /// <summary>
        /// As soon as an event arrives, a PDF invoice is generated and this invoice is uploaded to the DocumentService.
        /// </summary>
        /// <param name="eventData"></param>
        [UnitOfWork]
        public async Task HandleEventAsync(InvoiceAttestedAckEto eventData)
        {
            var invoice = await _invoiceManager.SetAttestedAckAsync(eventData.InvoiceId, eventData.CorrelationId);
            byte[] pdfArray = await _invoiceManager.CreateInvoicePdf(eventData.InvoiceId, false);
            
            // Upload to document service
            await _documentsAppService.UploadAsync(new DocumentUploadDto
            {
                FileContent = pdfArray,
                Filename = invoice.SequenceNumber + ".pdf"
            });
            
            // Create document in document service
            var documentCreateDto = new DocumentCreateDto
            {
                Index = 0,
                Description = invoice.Subject,
                Collection = null
            };
            await _documentsAppService.CreateAsync(documentCreateDto);
        }
    }
    

    I assume I might need to have client proxies as well?

    Best regards

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Yes, You need to create static proxy for DocumentService in your InvoiceService service and create InvoiceService proxy in your DocumentService

    Thanks.

  • User Avatar
    0
    carl.hallqvist created

    Thanks, one step in right direction I think. Got this now:

    [18:48:59 INF] Found 1 events in the inbox.
    [18:48:59 ERR] Could not get HttpClientProxyConfig for DocumentService.Documents.IDocumentsAppService.
    Volo.Abp.AbpException: Could not get HttpClientProxyConfig for DocumentService.Documents.IDocumentsAppService.
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
       at DocumentService.Documents.DocumentsClientProxy.UploadAsync(DocumentUploadDto input) in /app/InvoiceService/ClientProxies/GeoTicket/DocumentService/Documents/DocumentsClientProxy.Generated.cs:line 55
       at InvoiceService.InvoiceAttestedAckEventHandler.HandleEventAsync(InvoiceAttestedAckEto eventData) in /app/InvoiceService/Services/Invoices/InvoiceAttestedAckEventHandler.cs:line 38
       at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType)
       at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List`1 exceptions, InboxConfig inboxConfig)
       at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List`1 exceptions)
       at Volo.Abp.EventBus.RabbitMq.RabbitMqDistributedEventBus.ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig)
       at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
       at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
       at Volo.Abp.EventBus.Distributed.InboxProcessor.TimerOnElapsed(AbpAsyncTimer arg)
       at Volo.Abp.Threading.AbpAsyncTimer.Timer_Elapsed()
    1
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need to create static proxy for DocumentService in your InvoiceService service and create InvoiceService proxy in your DocumentService

    Can you share your Static Proxy code? You can also share your project source code.

    liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    carl.hallqvist created

    Thanks, I’ve made some progress. After rearranging the static client proxies as follows:

    MyProject.InvoiceService/MyProjectInvoiceServiceModule.cs
    
    // Prepare for static client proxy generation
    context.Services.AddStaticHttpClientProxies(
        typeof(DocumentServiceContractsModule).Assembly, 
        remoteServiceConfigurationName: "Default"
    );
    
    // Include the generated app-generate-proxy.json in the virtual file system
    Configure<AbpVirtualFileSystemOptions>(options =>
    {
        options.FileSets.AddEmbedded<InvoiceServiceModule>();
    });
    

    it works better. I’ve also added values in appsettings.json (as well as in the Helm charts) as follows:

    "IdentityClients": {
        "Default": {
          "GrantType": "client_credentials", 
          "ClientId": "_InvoiceService",
          "ClientSecret": "1q2w3e*",
          "Authority": "http://myproject-authserver", 
          "Scope": "DocumentService",
          "RequireHttps": "false"
        }
      },
    

    Gives:

    [19:25:49 ERR] Could not retrieve the OpenId Connect discovery document! ErrorType: PolicyViolation. Error: Issuer name does not match authority: https://auth.staging.myproject.io/
    Volo.Abp.AbpException: Could not retrieve the OpenId Connect discovery document! ErrorType: PolicyViolation. Error: Issuer name does not match authority: https://auth.staging.myproject.io/
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetDiscoveryResponse(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.CreateClientCredentialsTokenRequestAsync(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetTokenResponse(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetAccessTokenAsync(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetAccessTokenOrNullAsync(String identityClientName)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.TryAuthenticateAsync(HttpClient client, String identityClientName)
       at Volo.Abp.Http.Client.IdentityModel.IdentityModelRemoteServiceHttpClientAuthenticator.Authenticate(RemoteServiceHttpClientAuthenticateContext context)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
       at DocumentService.Documents.DocumentsClientProxy.UploadAsync(DocumentUploadDto input) in /app/InvoiceService/ClientProxies//DocumentService/Documents/DocumentsClientProxy.Generated.cs:line 55
       at InvoiceService.InvoiceAttestedAckEventHandler.HandleEventAsync(InvoiceAttestedAckEto eventData) in /app/InvoiceService/Services/Invoices/InvoiceAttestedAckEventHandler.cs:line 38
       at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType)
       at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List`1 exceptions, InboxConfig inboxConfig)
       at System.AbpExceptionExtensions.ReThrow(Exception exception)
       at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List`1 exceptions)
       at Volo.Abp.EventBus.RabbitMq.RabbitMqDistributedEventBus.ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig)
       at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
       at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
       at Volo.Abp.EventBus.Distributed.InboxProcessor.TimerOnElapsed(AbpAsyncTimer arg)
       at Volo.Abp.Threading.AbpAsyncTimer.Timer_Elapsed()
    

    Trying to use external DNS instead:

    "IdentityClients": {
      "Default": {
        "GrantType": "client_credentials", 
        "ClientId": "_InvoiceService",
        "ClientSecret": "1q2w3e*",
        "Authority": "https://auth.staging.myproject.io", 
        "Scope": "DocumentService",
        "RequireHttps": "true"
      }
    },
    

    Gives:

    [19:31:44 ERR] The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
    System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
     ---> System.TimeoutException: A task was canceled.
     ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
       at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
       at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
       at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
       at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core|4_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
       at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|4_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
       at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
       at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
       at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
       at IdentityModel.Client.HttpClientDiscoveryExtensions.GetDiscoveryDocumentAsync(HttpMessageInvoker client, DiscoveryDocumentRequest request, CancellationToken cancellationToken)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetDiscoveryResponse(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.CreateClientCredentialsTokenRequestAsync(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetTokenResponse(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetAccessTokenAsync(IdentityClientConfiguration configuration)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.GetAccessTokenOrNullAsync(String identityClientName)
       at Volo.Abp.IdentityModel.IdentityModelAuthenticationService.TryAuthenticateAsync(HttpClient client, String identityClientName)
       at Volo.Abp.Http.Client.IdentityModel.IdentityModelRemoteServiceHttpClientAuthenticator.Authenticate(RemoteServiceHttpClientAuthenticateContext context)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
       at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, ClientProxyRequestTypeValue arguments)
       at DocumentService.Documents.DocumentsClientProxy.UploadAsync(DocumentUploadDto input) in /app/InvoiceService/ClientProxies//DocumentService/Documents/DocumentsClientProxy.Generated.cs:line 55
       at InvoiceService.InvoiceAttestedAckEventHandler.HandleEventAsync(InvoiceAttestedAckEto eventData) in /app/InvoiceService/Services/Invoices/InvoiceAttestedAckEventHandler.cs:line 38
       at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType)
       at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List`1 exceptions, InboxConfig inboxConfig)
       at System.AbpExceptionExtensions.ReThrow(Exception exception)
       at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List`1 exceptions)
       at Volo.Abp.EventBus.RabbitMq.RabbitMqDistributedEventBus.ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig)
       at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
       at Volo.Abp.EventBus.Distributed.InboxProcessor.RunAsync()
       at Volo.Abp.EventBus.Distributed.InboxProcessor.TimerOnElapsed(AbpAsyncTimer arg)
       at Volo.Abp.Threading.AbpAsyncTimer.Timer_Elapsed()
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Try to set ValidateIssuerName and ValidateEndpoints to false

    "IdentityClients": {
        "Default": {
          "GrantType": "client_credentials", 
          "ClientId": "_InvoiceService",
          "ClientSecret": "1q2w3e*",
          "Authority": "http://myproject-authserver", 
          "Scope": "DocumentService",
          "RequireHttps": "false",
          "ValidateIssuerName": false,
          "ValidateEndpoints": false
        }
      },
    
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on October 30, 2025, 06:33