dasMulli / dotnet-win32-service

Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
MIT License
451 stars 57 forks source link

Can't get the asp.net core mvc sample work #52

Closed zhenmin-peng closed 6 years ago

zhenmin-peng commented 6 years ago

Run the following cmds in elevated powershell prompt

cd samples\MvcTestService
dotnet restore
dotnet run --register-service --preserve-working-directory

And open up http://localhost:50250/ (url is from launchsetting.json) but says "This site can’t be reached"

Also tried it in the interactive mode which seemed to work fine.

Anything else I forgot to do to make it work? Many thanks.

dasMulli commented 6 years ago

There are a two issues at work here:

  1. launchSettings.json makes the CLI set the ASPNETCORE_URLS environment variable before running the program. As you can see in the sample Program.cs, there is no capturing of environment variables implemented so parameter is added to the service registration.

  2. There is a bug in ASP.NET Core's default WebHost builder that prevents the app's command line config to actually set the URL. This will be fixed in 2.1.0 but until then it requires a workaround. See https://github.com/aspnet/MetaPackages/issues/221

I'll fix number 2 by adding the workaround to the sample app so that dotnet run …… --urls http://*:50250 will work (since that may be needed in production) but I'd rather not bloat it with trying to read development-time settings.

dasMulli commented 6 years ago

@alphaeleven I've merged the workaround in https://github.com/dasMulli/dotnet-win32-service/pull/53.

Is that sufficient information for you?

I'm not sure if I should make any efforts to fix (1) since it really seems a little out of scope for a sample..

zhenmin-peng commented 6 years ago

@dasMulli Thank you so much for your quick response and fix.

The workaround does the trick. And agree that there is no need to do the fix (1) as it is a bit irrelevant.