I am new to blazor and trying to understand the differences between different hosting models.

From what I read I understand Blazor Server side and Blazor WebAssembly Hosted have server side code, both uses Signal R to communicate with the Client.

So what is the difference between them? Where is the client side of theses deployed to? What difference is in their connection with Server? If the Web App inturn calls a 3rd party web API how is the call routed?

One difference I found was in the project structure. Blazor Server side has only one project (with a Data Folder). Blazor WebAssembly Hosted has 3 projects(.Server, .Client and .Shared).

blazor is two components

a javascript engine that sends events to blazor, and manages updates to the dom. via javascript interop, it can execute javascript commands sent by the blazor engine

the blazor component engine that send html updates to javascript engine.

blazor server:
if blazor is hosted on the server, the javascript engine opens signal/r connection to the server which hosts the blazor engine. all communication is over the signal/r connection. the blazor engine has all the state.

The blazor code has full access to server services, and .net libraries.

blazor client:
the blazor code is compiled to WASM. the javascript engine is responsible for loading the blazor code, which is just a url. the javascript and blazor communicate over the browser messaging services. no signal/r is required. actually no server code is required at all, it can be a static site.

if the blazor client needs to call a server, it can use any method supported by the javascript, as WASM is a sandbox with no network access. HttpClient for example uses javascript interop to make network calls.

Because of the sandbox, and the reduced services of the blazor WASM runtime support, many nuget packages will not work with blazor client.

when creating a blazor wasm project you have two options:

1) standalone static blazor site
2) a blazor static site and webapi project to host the blazor static site. the blazor code would use httpclient to call the webapi server.

A lot has been said before, and I will add it based on my experience:

  • ssr : is conducive to quick response and debugging, and it is very convenient to develop without writing the controller.
  • wasm : the first startup of deployment is very slow, and debugging greatly affects efficiency.
  • The difference between Blazor WASM and Blazor server is well documented.

    Blazor Server
    Blazor WebAssembly

    A hosted Blazor WASM project is just a way to host Blazor WASM (client) in a ASP.NET Core Web Application. If you look at the server project reference you'll see it references the client application. If you take a look at the fallback route, it returns index,.htm which is the Blazor WASM application.

    https://stackoverflow.com/questions/58093386/whats-the-difference-between-asp-net-core-hosted-and-server-side-blazor-really

    @AgaveJoe , thanks for the reply.

    I am looking for how the application works really.
    So when a user first go to the Hosted WASM what happens? Does the client code get downloaded to the device? If it does then when the client makes call to an API does the call go through the server? What is the use of SignalR in WASM hosted?It kind of makes sense in Server side , as the difference in html is rendered by server to client, but how does that work in hosted.

    Thanks

    So when a user first go to the Hosted WASM what happens? Does the client code get downloaded to the device? If it does then when the client makes call to an API does the call go through the server?

    A request to the server's root returns the Blazor WASM application; index.html. Try adding /WeatherForecast to the end of the URL and you'll see the results of executing the WeatherForecastController on the server.

    What is the use of SignalR in WASM hosted?

    I'm not sure where you are coming up with this notion. SignalR is not a default configuration in Blazor WASM. SignalR must be configured in Blazor WASM if you wish to use SignalR.

    It kind of makes sense in Server side , as the difference in html is rendered by server to client, but how does that work in hosted.

    It's exactly the same concept. The Blazor application has to be hosted somewhere. Why not host it with an ASP.NET Core application? They you don't have to worry about CORS or having two separate web applications.

    Have you read the links in my first post?