2
votes

I have tried adding ServiceStack-references to a client-side Blazor project, but I run into problems after adding ServiceStack.HttpClient via NuGet.

Currently, VS2019 will tell me that:

Cannot find declaration of exported type 'System.Threading'

and when ask/look around, they say that:

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.

and

at present Mono WASM has no support for threading; check the repo https://github.com/lrz/mono-wasm-mono for more info

Am I getting it correctly:

  • ServiceStack requires System.Threading
  • WebAssembly and thus Blazor does not support references to System.Threading
  • Meaning that ServiceStack cannot be used in a Blazor app
2

2 Answers

3
votes

ServiceStack's Blazor WASM Template is being maintained by Sebastian Faltoni at https://github.com/nukedbit/blazor-wasm-servicestack

Which can be installed with the x dotnet tool:

$ dotnet tool install -g x

and created with:

$ x new nukedbit/blazor-wasm-servicestack ProjectName

Or for an installation-free alternative use ServiceStack's online project template builder: https://servicestack.net/start#community

It includes integration with a Blazor Service Client which can be created at:

var client =  BlazorClient.Create("https://localhost:5001")

It currently returns a pre-configured JsonHttpClient that removes all HttpClient features that Blazor WASM doesn't support. Over time we'll include more features as they're supported in Blazor.

@Issac is incorrect about ServiceStack using Web Sockets, ServiceStack doesn't use Web Sockets in any of its libraries and BlazorClient is a Service Client using .NET's HttpClient which Blazor WASM does support.

1
votes

@Ted,

Blazor does not run in a multi-thread environment. Blazor (mono-wasm) runs in the same sandbox of JavaScript, in the same UI thread. No multi-threading, no concurrent or parallel programming. As I've said before, I've never heard of ServiceStack, but I guess that ServiceStack.HttpClient cannot be used in Blazor client side, as "Blazor HttpClient" is based on HttpMessageHandler, and it is adapted to work as an Ajax agent; that is, HttpClient communicate with the Back End via the JavaScript Fetch Web API, whereas ServiceStack, I believe, perform the traditional http client calls, employing Web Sockets, which is not supported in Blazor (mono-wasm). In Asp.Net Core 5.0 it is expected that Blazor client side would support Web Sockets, after mono would be replaced.

No, the ServiceStack cannot be used in a Blazor app

Hope this helps...