Starts in:
1 DAY
13 HRS
26 MIN
13 SEC
Starts in:
1 D
13 H
26 M
13 S
Open Closed

Using C# Generated Client Proxies in a new Default Blazor Wasm Template #3255


User avatar
0
falsharif created

Dear Team, i used the abp generate-proxy -t csharp -url https://localhost:44358 command and generated c# client proxies. Now i created a new empty blazor app using "dotnet new blazorwasm -o ProMailNet.BlazorWasm" and would like to use this proxy by injecting it. Is there any way to achieve that ?

I was able to inject it into my program.cs and referenced the project http.client.

builder.Services.AddScoped<MailboxClientProxy>();

but when i try to call a method from the mailboxclientproxy :

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at Uncaught (in promise) Error: Volo.Abp.AbpException: WebAssemblyCachedApplicationConfigurationClient should be initialized before using it.

would really appreciate your help. as i am trying to create an empty blazor app but use the proxies. The reason for that is that currently my blazor application hosted on https://uat.promailnet.com takes upto 6 seconds before reaching the appliction-configuration call which is leading to super slow load time. everytime you refresh it does the same thing. it caches everything else, but this call takes 6 seconds to initiate, so im starting with a blank template as i only require the proxies for some app services. I am handling everything else

  • ABP Framework version: 5.2
  • UI type:/ Blazor
  • DB provider: EF Core /
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need to bootstrap the abp module system in your blazor wasm project.

    public class Program
    {
        public async static Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
    
            var application = await builder.AddApplicationAsync<MyProjectNameBlazorModule>(options =>
            {
                options.UseAutofac();
            });
    
            var host = builder.Build();
    
            await application.InitializeApplicationAsync(host.Services);
    
            await host.RunAsync();
        }
    }
    
    

    https://docs.abp.io/en/abp/latest/API/Static-CSharp-API-Clients

  • User Avatar
    0
    falsharif created

    Hello, thanks for the advice, ok so now its calling the api endpoint but the token isnt being passed and my endpoints returns Unauthorized:

    I have my own login page which was implemented and working on my original blazor UI project. i copied the same config to this project as follows

    public override void ConfigureServices(ServiceConfigurationContext context) { var environment = context.Services.GetSingletonInstance<IWebAssemblyHostEnvironment>(); var builder = context.Services.GetSingletonInstance<WebAssemblyHostBuilder>();

            ConfigureAuthentication(builder);
            ConfigureHttpClient(context, environment);
            ConfigureBlazorise(context);
            ConfigureRouter(context);
            ConfigureUI(builder);
            ConfigureAutoMapper(context);
            
            context.Services.AddScoped&lt;TokenServerAuthenticationStateProvider&gt;();
            context.Services.AddScoped&lt;AuthenticationStateProvider&gt;(provider => provider.GetRequiredService&lt;TokenServerAuthenticationStateProvider&gt;());
        }
    

    Would it be possible to create a working example project ? would really appreciate it , already my application is down to 1.9 seconds load now, just need to fix the token header.

  • User Avatar
    0
    falsharif created

    Update : I got the JWT token to work but i am having a weird issue while generating the proxies using : abp generate-proxy -t csharp -u https://localhost:44358

    some of the proxies generated have this issue for some of the functions, i cant see anything in common with those functions :

    public virtual GroupDto GetByFriendlyUrl(string url, Guid pmnId) { //Client Proxy does not support the synchronization method, you should always use asynchronous methods as a best practice throw new System.NotImplementedException(); }

    However , my function is actually Async as can be seen here :

    public interface IGroupAppService : IApplicationService { Task<PagedResultDto<GroupDto>> GetListAsync(GetGroupsInput input);

        Task&lt;GroupDto&gt; GetAsync(Guid id);
    
        Task DeleteAsync(Guid id);
    
        Task&lt;GroupDto&gt; CreateAsync(CreateOrUpdateGroupInput input);
    
        Task&lt;GroupDto&gt;  UpdateAsync(CreateOrUpdateGroupInput input);
    
        Task&lt;List&lt;GroupDto&gt;> GetMyGroups(Guid pmnId);
        Task&lt;GroupDto&gt; GetByFriendlyUrl(string url, Guid pmnId);
        Task SetAllGroupsFullPath();
    }
    
  • User Avatar
    0
    falsharif created

    Update : I figured it out , it was the names of the functions , the name convention needed the word Async at the end of function names !

  • User Avatar
    1
    falsharif created

    And btw thanks alot , you always provide timely and great support, much appreciated :)

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