簡體   English   中英

從 Blazor Webassembly 應用程序調用服務時 IIS 中的 Grpc.Core.ClientBase 錯誤

[英]Grpc.Core.ClientBase Error in IIS when service invoked from Blazor Webassembly app

我在瀏覽器控制台中出現以下錯誤,不允許 Blazor Webassembly 應用程序繼續使用 grpc API:

System.ArgumentException:服務代理 CalibrationSaaS.Application.Services.IBasicsServices`1[ProtoBuf.Grpc.CallContext] 的基本類型 Grpc.Core.ClientBase 缺少合適的 CallInvoker API

發生這種情況的代碼如下:

var httpClient = new HttpClient(new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()));

   using (var channel = Grpc.Net.Client.GrpcChannel.ForAddress(builder.Configuration["Kestrel:Endpoints:Http3:Url"], new GrpcChannelOptions
    {
        HttpClient = httpClient
    }))
    {                
        var a = channel.CreateGrpcService<Application.Services.IBasicsServices<CallContext>>(); //The error happens in this line of code
        var b = await a.GetRoles(CallContext.Default); //This method is implemented
        return b;
    }

僅當應用程序發布在相應的 IIS 中時,才會發生此錯誤,在開發 IDE 調試環境中正常工作。

有誰知道問題可能是什么?

這是他的創建者及時修復的第三方庫問題(protobuf-net)。 如果您需要更多信息,可以查看此線程:

https://github.com/protobuf-net/protobuf-net.Grpc/issues/247

要解決此問題,請將庫從 Github 更新到 1.0.171 版本,並將以下配置添加到 Blazor 項目文件中:

<PropertyGroup> 
...
<BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking> 
...
</PropertyGroup>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM