Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Server Deployed as a Window Service to host Client Blazor Server App

$
0
0

I am an apprentice working in a bank and I have been tasked with creating a Blazor Web Application. I have opted for Blazor Server App for the full front/back end experiecne as it is easier.

The issue arises in regards to deployment. I am being asked to deploy the application as a "Window Service". Essentially I am being told that I need to have a bare bone server with nothing in it -- no controllers, no pages, no data .. Nothing!. It's only use is to act as a container for my Blazor Server app, which has all the pages, data, logic, database interactions etc. The server is meant to be deployed as a window service and only act as a container.

  • What does this mean?
  • How do I achieve this?!
  • How do I get the server to serve my client without any API or controllers or anything?
  • How do I interact with the client?

My manager is unresponsive and clearly doesn't want to help. He keeps saying that it is possible and that he has done it before but can't remember how, sigh...

This is what I found on the web. It shows how to deploy a Blazor App as a window service but, that's only 1 part. How do I get it to serve the client which is a fully functioning Blazor Server app:

Step 1. Install Microsoft.Extensions.Hosting.WindowsServices fromNuGet Package Manager.

Step 2. Add to program.cs
using Microsoft.Extensions.Hosting.WindowsServices;

Step 3. Change
var builder = WebApplication.CreateBuilder(args);
to the following:

var builder = WebApplication.CreateBuilder(new WebApplicationOptions() {    ContentRootPath = WindowsServiceHelpers.IsWindowsService()         ? AppContext.BaseDirectory         : default,    Args = args});

Step 4. Before
var app = builder.Build();
add the following code:
builder.Host.UseWindowsService();

Step 5. Publish the app to folder

Step 6. Run cmd.exe as administrator.

Step 7. Create a Service with the following command:
sc create <SERVICE_NAME> binPath="<BIN_PATH>"

Example:

sc create MySerice binPath="C:\MySolution\MyProject\bin\Release\net7.0\publish\MyProject.exe"

Step 8. Start the Service with the following command:
net start <SERVICE_NAME>

Example: net start MySerice

What do I need to do to add the client and where?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>