ServiceStack:添加 Blazor 支持?
ServiceStack: Adding Blazor support?
我曾尝试将 ServiceStack 引用添加到客户端 Blazor 项目,但在通过 NuGet 添加 ServiceStack.HttpClient 后我 运行 遇到了问题。
目前,VS2019 会告诉我:
Cannot find declaration of exported type 'System.Threading'
当 ask/look around 时,他们说:
Blazor is built using mono-wasm as the base .NET framework
implementation, and in this case I believe it's a missing method in
mono-wasm that's the issue.
和
at present Mono WASM has no support for threading; check the repo
https://github.com/lrz/mono-wasm-mono for more info
我理解正确吗:
- ServiceStack 需要
System.Threading
- WebAssembly,因此 Blazor 不支持对
System.Threading
的引用
- 意味着 ServiceStack 不能在 Blazor 应用程序中使用
@Ted,
Blazor 不会在 multi-thread 环境中 运行。 Blazor (mono-wasm) 运行 在 JavaScript 的同一沙箱中,在同一 UI 线程中。没有 multi-threading,没有并发或并行编程。正如我之前所说,我从未听说过 ServiceStack,但我猜 ServiceStack.HttpClient 不能在 Blazor 客户端中使用,因为 "Blazor HttpClient" 是基于 HttpMessageHandler 的,它适合作为Ajax 代理人;也就是说,HttpClient 通过 JavaScript Fetch Web API 与后端通信,而我认为 ServiceStack 使用 Web 套接字执行传统的 http 客户端调用,这在 Blazor 中不受支持(mono-wasm).在 Asp.Net Core 5.0 中,预计 Blazor 客户端将在单声道被替换后支持 Web 套接字。
不,ServiceStack 不能在 Blazor 应用程序中使用
希望这对您有所帮助...
ServiceStack 的 Blazor WASM 模板由 Sebastian Faltoni at https://github.com/nukedbit/blazor-wasm-servicestack
维护
其中可以安装x dotnet tool:
$ dotnet tool install -g x
并创建于:
$ x new nukedbit/blazor-wasm-servicestack ProjectName
或者 installation-free 替代方法是使用 ServiceStack 的在线项目模板生成器:
https://servicestack.net/start#community
它包括与可在以下位置创建的 Blazor 服务客户端的集成:
var client = BlazorClient.Create("https://localhost:5001")
它目前 returns pre-configured JsonHttpClient
删除了 Blazor WASM 不支持的所有 HttpClient 功能。随着时间的推移,我们将包含更多 Blazor 支持的功能。
@Issac 关于 ServiceStack 使用 Web 套接字的说法不正确,ServiceStack 在其任何库中都不使用 Web 套接字,BlazorClient
是一个使用 .NET 的 HttpClient 的服务客户端,Blazor WASM 确实支持它。
我曾尝试将 ServiceStack 引用添加到客户端 Blazor 项目,但在通过 NuGet 添加 ServiceStack.HttpClient 后我 运行 遇到了问题。
目前,VS2019 会告诉我:
Cannot find declaration of exported type 'System.Threading'
当 ask/look around 时,他们说:
Blazor is built using mono-wasm as the base .NET framework implementation, and in this case I believe it's a missing method in mono-wasm that's the issue.
和
at present Mono WASM has no support for threading; check the repo https://github.com/lrz/mono-wasm-mono for more info
我理解正确吗:
- ServiceStack 需要
System.Threading
- WebAssembly,因此 Blazor 不支持对
System.Threading
的引用
- 意味着 ServiceStack 不能在 Blazor 应用程序中使用
@Ted,
Blazor 不会在 multi-thread 环境中 运行。 Blazor (mono-wasm) 运行 在 JavaScript 的同一沙箱中,在同一 UI 线程中。没有 multi-threading,没有并发或并行编程。正如我之前所说,我从未听说过 ServiceStack,但我猜 ServiceStack.HttpClient 不能在 Blazor 客户端中使用,因为 "Blazor HttpClient" 是基于 HttpMessageHandler 的,它适合作为Ajax 代理人;也就是说,HttpClient 通过 JavaScript Fetch Web API 与后端通信,而我认为 ServiceStack 使用 Web 套接字执行传统的 http 客户端调用,这在 Blazor 中不受支持(mono-wasm).在 Asp.Net Core 5.0 中,预计 Blazor 客户端将在单声道被替换后支持 Web 套接字。
不,ServiceStack 不能在 Blazor 应用程序中使用
希望这对您有所帮助...
ServiceStack 的 Blazor WASM 模板由 Sebastian Faltoni at https://github.com/nukedbit/blazor-wasm-servicestack
维护其中可以安装x dotnet tool:
$ dotnet tool install -g x
并创建于:
$ x new nukedbit/blazor-wasm-servicestack ProjectName
或者 installation-free 替代方法是使用 ServiceStack 的在线项目模板生成器: https://servicestack.net/start#community
它包括与可在以下位置创建的 Blazor 服务客户端的集成:
var client = BlazorClient.Create("https://localhost:5001")
它目前 returns pre-configured JsonHttpClient
删除了 Blazor WASM 不支持的所有 HttpClient 功能。随着时间的推移,我们将包含更多 Blazor 支持的功能。
@Issac 关于 ServiceStack 使用 Web 套接字的说法不正确,ServiceStack 在其任何库中都不使用 Web 套接字,BlazorClient
是一个使用 .NET 的 HttpClient 的服务客户端,Blazor WASM 确实支持它。