无法在UNO Platform WebAssembly中创建GRPCCHANNEL(System.NullReferenceException)

发布于 2025-02-06 07:49:21 字数 1081 浏览 2 评论 0 原文

我正在尝试使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷雨优美回忆 2025-02-13 07:49:21

好的,我分析了您的代码,并在您的代码中发现了4个问题:

  1. 您使用的是Blazor IOC容器。 UNO并非旨在使用开箱即用。 有一些方法可以使用一些方法>,但是还有更多工作要做。为了解决此问题,我简单地将GRPC服务初始化移至 mainpage.xaml.cs 中。这不是生产质量,但它的目的是演示GRPC。
  2. 您正在调用 sync .incrementCount()的版本。在WASM上这是不可能的,因为它不可能阻止WASM中的主线程(实际上,这是可能的,但是您需要使用隐藏在JavaScript深处的primitives,而且它不会解决您的问题) 。这就是为什么在Blazor上您需要调用 .incrementCountAsync()。 WASM上也存在相同的要求。
  3. 您页面的XAML使用< grid> 没有任何 rows ,因此每个元素都被划出一个。我用< stackpanel> 代替了它,以获得更好的结果。
  4. 由于主机名 +端口略有不同,因此需要激活服务器上的CORS。

我在a

Ok I analyzed your code and I found 4 problems in your code:

  1. You were using the Blazor IoC Container. Uno is not designed to use it out-of-the-box. There some ways to use a container, but there's more work to do. To fix this, I simply moved the gRPC service initialization into the MainPage.xaml.cs instead. That's not production quality, but it serves the purpose of demoing gRPC.
  2. You were calling the SYNC version of .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.
  3. The XAML of your page were using a <Grid> without any rows, so each elements were drawn one over the other. I replaced it with a <StackPanel> to have a better result.
  4. Is was required to activate CORS on the server because the host name + port is slightly different.

I published a working version on a Fork I did of your project IT WORKS!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文