我正在尝试使用 grpc-web 进行 uno平台的样本。
因此,我受到了本文提供的内容。我遵循文章的说明,并创建了使用 grpc-web 的天气服务的A Blazorapp 。之后,我还提供了另一项服务,即计数器服务,如这个grpc-web示例。
在工作后,我添加了 uno平台WebAssembly 应用程序以替换BlazorApp 客户端。
当前问题:
尝试创建 grpcChannel
应用程序获取 System.NullReferenceException
。
用于创建通道的代码段看起来像:
var baseUri = "https://localhost:44366";
var channel = GrpcChannel.ForAddress(baseUri, new GrpcChannelOptions());
这与 blazorapp 中使用的代码完全相同。
可以在 blazorapp 和 uno平台webAssembly 的示例代码 “ nofollow noreferrer”>此存储库。
任何想法/建议/帮助将不胜感激。
I am trying to do a sample of Uno Platform using gRPC-Web.
Therefore I got inspired by the content provided by this article. I followed the instructions of the article and created a BlazorApp which used a weather service with gRPC-Web. After that I also included an other service, the counter service, as seen in this gRPC-Web example.
After everthing was working, I added a Uno Platform WebAssembly app to replace the BlazorApp client.
Current Problem:
When trying to create a GrpcChannel
the application gets a System.NullReferenceException
.
The code snippet for creating the channel looks like this:
var baseUri = "https://localhost:44366";
var channel = GrpcChannel.ForAddress(baseUri, new GrpcChannelOptions());
This is exactly the same code as used in the BlazorApp.
The sample code for the BlazorApp and the Uno Platform WebAssembly can be found in this repository.
Any idea/suggestion/help would be appreciated.
发布评论
评论(1)
好的,我分析了您的代码,并在您的代码中发现了4个问题:
mainpage.xaml.cs
中。这不是生产质量,但它的目的是演示GRPC。.incrementCount()
的版本。在WASM上这是不可能的,因为它不可能阻止WASM中的主线程(实际上,这是可能的,但是您需要使用隐藏在JavaScript深处的primitives,而且它不会解决您的问题) 。这就是为什么在Blazor上您需要调用.incrementCountAsync()
。 WASM上也存在相同的要求。< grid>
没有任何 rows ,因此每个元素都被划出一个。我用< stackpanel>
代替了它,以获得更好的结果。我在a
Ok I analyzed your code and I found 4 problems in your code:
MainPage.xaml.cs
instead. That's not production quality, but it serves the purpose of demoing gRPC..IncrementCount()
. This is not possible on WASM since it's not possible to block the main thread in WASM (actually, it's possible, but you need to use primitives hidden deep in JavaScript and it won't solve your problem anyway). That's why on Blazor you need to call.IncrementCountAsync()
. The same requirements are present on WASM.<Grid>
without any rows, so each elements were drawn one over the other. I replaced it with a<StackPanel>
to have a better result.I published a working version on a Fork I did of your project IT WORKS!!