Open Closed

Need a guide about chat module in blazor server. #4151


User avatar
0
mc86 created
  • UI type: Blazor-server
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

i flowed the doc and added the chat module in a **microservice ** . add the volo.chat to the {projectname}.blazor then added the

  app.Use(async (httpContext, next) =>
            {
                var accessToken = httpContext.Request.Query["access_token"];

                var path = httpContext.Request.Path;
                if (!string.IsNullOrEmpty(accessToken) &&
                    (path.StartsWithSegments("/signalr-hubs/chat")))
                {
                    httpContext.Request.Headers["Authorization"] = "Bearer " + accessToken;
                }

                await next();
            });

to the blazor server app. but now there is an error

[blazor_e61ab55f-b]: [11:10:27 INF] Request finished HTTP/1.1 POST https://localhost:44314/signalr-hubs/chat/negotiate?negotiateVersion=1 - 0 - 400 0 - 0.7379ms
[blazor_e61ab55f-b]: [11:10:27 WRN] Unhandled exception rendering component: Response status code does not indicate success: 400 (Bad Request).
[blazor_e61ab55f-b]: System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
[blazor_e61ab55f-b]: at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.NegotiateAsync(Uri url, HttpClient httpClient, ILogger logger, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.GetNegotiationResponseAsync(Uri uri, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.SelectAndStartTransport(TransferFormat transferFormat, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsyncCore(TransferFormat transferFormat, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsync(TransferFormat transferFormat, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncCore(CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncInner(CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsync(CancellationToken cancellationToken)
[blazor_e61ab55f-b]: at Volo.Chat.Blazor.Components.MessagesToolbarItem.OnInitializedAsync()
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
[blazor_e61ab55f-b]: at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
[blazor_e61ab55f-b]: [11:10:27 ERR] Unhandled exception in circuit 'AbGz5Sf6tRmRB9LTKUMsV1s_0qNpKbp2iTBg41nPdFE'.

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

    Hi,

    You don't need to add these codes.

    Here are my steps:

    • Add chat packages to the service. for example: add chat packages to the AdministrationService.
      • Run abp add-package Volo.Chat.Application command in the *.AdministrationService.Application folder
      • Run abp add-package Volo.Chat.Application.Contracts command in the *.AdministrationService.Application.Contracts folder
      • Run abp add-package Volo.Chat.Domain command in the *.AdministrationService.Domain folder
      • Run abp add-package Volo.Chat.Domain.Shared command in the *.AdministrationService.Domain.Shared folder
      • Run abp add-package Volo.Chat.EntityFrameworkCore command in the *.AdministrationService.EntityFrameworkCore folder
      • Run abp add-package Volo.Chat.HttpApi command in the *.AdministrationService.HttpApi folder
      • Run abp add-package Volo.Chat.HttpApi.Client command in the *.AdministrationService.HttpApi.Client folder
      • Run abp add-package Volo.Chat.HttpApi.Client command in the *.AdministrationService.HttpApi.Client folder
      • Configure database tables
        • Add builder.ConfigureChat(); to the OnModelCreating method of AdministrationServiceDbContext class
        • Make AdministrationServiceDbContext implement the IChatDbContext interface
        • Open AdministrationServiceEntityFrameworkCoreModule and add options.ReplaceDbContext<IChatDbContext>();
        • Use dotnet ef ... command to add migrations & update database.
      • Configure Blazor project
        • Add <PackageReference Include="Volo.Chat.Blazor.Server" Version="6.0.1" /> to csproj file.
        • Add <PackageReference Include="Volo.Chat.SignalR" Version="6.0.1" /> to csproj file.
        • Add [DependsOn(typeof(ChatSignalRModule), typeof(ChatBlazorServerModule))] to the *BlazorModule
        • Configure gateway
          {
              "ServiceKey": "Chat Service",
              "DownstreamPathTemplate": "/api/chat/{everything}",
              "DownstreamScheme": "https",
              "DownstreamHostAndPorts": [
                {
                  "Host": "localhost",
                  "Port": 44367 //Make sure the port same with your Administration Service
                }
              ],
              "UpstreamPathTemplate": "/api/chat/{everything}",
              "UpstreamHttpMethod": [ "Put", "Delete", "Get", "Post" ]
            },
          

    Run the project

    Now, it should be working for you:

  • User Avatar
    0
    mc86 created

    I flowed the guide setp by step there still has a error when search users is there something missing in the "Configure database tables"?

    An exception was thrown while activating Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions`1[[Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext, Volo.Abp.Identity.EntityFrameworkCore, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null]].
    [oaservice_265633f1-d]: Autofac.Core.DependencyResolutionException: An exception was thrown while activating Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions`1[[Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext, Volo.Abp.Identity.EntityFrameworkCore, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null]].
    [oaservice_265633f1-d]: ---> Volo.Abp.AbpException: No configuration found for Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore, Version=6.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60! Use services.Configure<AbpDbContextOptions>(...) to configure it.
    [oaservice_265633f1-d]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Configure[TDbContext](AbpDbContextOptions options, AbpDbContextConfigurationContext`1 context)
    
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi

    I explain it here

  • User Avatar
    0
    mc86 created

    I did all those steps.

    [oaservice_0b7dfe5d-7]: [16:42:27 ERR] An exception was thrown while activating Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions`1[[Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext, Volo.Abp.Identity.EntityFrameworkCore, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null]].
    [oaservice_0b7dfe5d-7]: Autofac.Core.DependencyResolutionException: An exception was thrown while activating Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext -> λ:Microsoft.EntityFrameworkCore.DbContextOptions`1[[Volo.Abp.Identity.EntityFrameworkCore.IdentityDbContext, Volo.Abp.Identity.EntityFrameworkCore, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null]].
    [oaservice_0b7dfe5d-7]: ---> Volo.Abp.AbpException: No configuration found for Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore, Version=6.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60! Use services.Configure<AbpDbContextOptions>(...) to configure it.
    [oaservice_0b7dfe5d-7]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Configure[TDbContext](AbpDbContextOptions options, AbpDbContextConfigurationContext`1 context)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.EntityFrameworkCore.DependencyInjection.DbContextOptionsFactory.Create[TDbContext](IServiceProvider serviceProvider)
    [oaservice_0b7dfe5d-7]: at Autofac.Extensions.DependencyInjection.AutofacRegistration.&lt;&gt;c__DisplayClass3_0.&lt;Register&gt;b__0(IComponentContext context, IEnumerable`1 parameters)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Activators.Delegate.DelegateActivator.&lt;ConfigurePipeline&gt;b__2_0(ResolveRequestContext ctxt, Action`1 next)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    [oaservice_0b7dfe5d-7]: --- End of inner exception stack trace ---
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
    [oaservice_0b7dfe5d-7]: at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
    [oaservice_0b7dfe5d-7]: at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
    [oaservice_0b7dfe5d-7]: at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
    [oaservice_0b7dfe5d-7]: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider`1.CreateDbContextAsync(IUnitOfWork unitOfWork)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider`1.CreateDbContextAsync(IUnitOfWork unitOfWork, String connectionStringName, String connectionString)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider`1.GetDbContextAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository`2.GetDbSetAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Identity.EntityFrameworkCore.EfCoreIdentityUserRepository.GetListAsync(String sorting, Int32 maxResultCount, Int32 skipCount, String filter, Boolean includeDetails, Nullable`1 roleId, Nullable`1 organizationUnitId, String userName, String phoneNumber, String emailAddress, Nullable`1 isLockedOut, Nullable`1 notActive, CancellationToken cancellationToken)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Identity.IdentityUserRepositoryExternalUserLookupServiceProvider.SearchAsync(String sorting, String filter, Int32 maxResultCount, Int32 skipCount, CancellationToken cancellationToken)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Users.UserLookupService`2.SearchAsync(String sorting, String filter, Int32 maxResultCount, Int32 skipCount, CancellationToken cancellationToken)
    [oaservice_0b7dfe5d-7]: at Volo.Chat.Users.ContactAppService.GetContactsAsync(GetContactsInput input)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.GlobalFeatures.GlobalFeatureInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Features.FeatureInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
    [oaservice_0b7dfe5d-7]: at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
    [oaservice_0b7dfe5d-7]: at lambda_method1488(Closure , Object )
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;g__Logged|12_1(ControllerActionInvoker invoker)
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeInnerFilterAsync&gt;g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    [oaservice_0b7dfe5d-7]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextExceptionFilterAsync&gt;g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Could you share a project with me that can reproduce the problem? shiwei.liang@volosoft.com thanks.

  • User Avatar
    0
    mc86 created

    thanks, already send it

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Because the project you provided can't build, I made an example for you.

    You are trying to add chat to a QaService, it needs more configuration:

    You can check the example my shared, in this example, I added Chat to ProductService

    • Add Volo.Abp.Identity.Pro.HttpApi.Client and IdentityService.Application.Contracts to HttpApi.Host project

    • Configure RemoteServices

          "RemoteServices": {
              "AbpIdentity": {
                "BaseUrl": "https://localhost:44325/",
                "UseCurrentAccessToken": "false"
              }
            },
            "IdentityClients": {
              "Default": {
                "GrantType": "client_credentials",
                "ClientId": "Qa_AdministrationService",
                "ClientSecret": "1q2w3e*",
                "Authority": "https://localhost:44322",
                "Scope": "IdentityService"
              }
            },
         ```
      
      
  • User Avatar
    0
    mc86 created

    Moved the chat module to the adminservice. it's working now Thanks for your time.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11