Is it possible to use ASP.NET Core Web API without IIS in a Windows Desktop application?
Asked Answered
A

2

10

Currently I'm trying to find a way to build a desktop app that hosts a browser window and uses JavaScript to communicate with a local ASP.NET Core Web API as the "backend":

enter image description here

All my searches lead to the suggestion that I should use IIS Express web server.

Unfortunately, IIS Express does not fit into my scenario, since I want the whole application to be installable and runnable by non-admin users.

Since IIS Express requires administrative permissions to install, this is out-of-scope to me.

My question:

Is there another way beside using IIS Express to run an ASP.NET Core Web API project?

I've read about the Kestrel server which seems to be what I am looking for, but I still don't get the big picture here.

Edit 1:

I've asked a somewhat releated question over at SE Software Recommendations.

Albumen answered 11/8, 2016 at 21:57 Comment(5)
Kestrel will work well here, have you tried?Jurywoman
Thanks, @Jurywoman — I'm still trying to understand what Kestrel really is. Am I right that it ships as part of .NET Core? So I could simply ship my application with those MB of .NET Core files and have Kestrel included? I also fear that it is kind of a "proof-of-concept" web server that is not fast/mature enough for a real-world scenario?Albumen
Yes, that's pretty much what it is. It's also cross platform so your app will pretty much run anywhere too.Jurywoman
As for whether it's POC or not, absolutely not the case. MS are fully supporting it and it now runs significantly faster than IIS, last I heard it could serve a tonne of requests per second.Jurywoman
Awesome, @DavidG. How about posting this as an answer here, so I can accept it?Albumen
J
6

I'm sure Kestrel will work well for you in this situation. It's a cross platform web server which is based on libuv which means it is super fast. The official benchmarks show just how much it outperforms standard IIS.

Jurywoman answered 11/8, 2016 at 22:6 Comment(3)
I've did some very simple comparisons between an IIS Express Web API and a Kestrel Web API. I've called both with Apache Bench (ab.exe). Results: IIS Express: 4013.10 [requests/sec] (mean), Kestrel: 4375.13 [requests/sec] (mean). So not that much of a difference.Albumen
There's likely some other bottleneck here then. Kestrel significantly outperforms IIS and IIS Express. you may be hitting your local machine disk, CPU or network limit. Benchmarking like this is incredibly nuanced and difficult.Jurywoman
Just for the records: It is also possible to use the Kestrel web server in a "normal" .NET Framework project, e.g. .NET 4.6.1. Simply add the Microsoft.AspNetCore.Server.KestrelNuGet package as a reference.Albumen
D
-1

To add to DavidG's answer.

Kestral is the correct solution IFF you want to run ASP.Net without IIS.

However this requires an open TCP port to work. Meaning that if you try to bind Kestral to port 80, AND the user has IIS installed. Kestral will fail to run.

You can get around this by using Katana to bind your website to a subdirectory within IIS. Unfortunately, this will often require Admin Rights.

Overall, you can basically use any OWIN server you want.

You can even put in some code to choose which OWIN server you use, based on the circumstances.

Delogu answered 15/8, 2016 at 5:55 Comment(6)
What are the other OWIN servers you are refering to?Albumen
Kestrel is also the answer if you want to run with IIS. You have to set IIS up as a reverse proxy.Jurywoman
I'm not sure that I'd be comfortable using that library as it hasn't been updated for 4 years and the project owner hasn't even bothered to keep the domain where it was hosted.Jurywoman
@Jurywoman My bad, I meant Katana. The OWIN names are really confusing. I recommend using Katana when using IIS.Delogu
Well OWIN is just a spec and Katana is the MS implementation of that I also don't know why you would use Katana when Kestrel will handle the job on it's own and if you want a fully hosted solution then IIS or Nginx would be more appropriate.Jurywoman
@Jurywoman I explained my reasoning in my answer. But in effect Katana is built on Windows Activation Service, which is effectively an API to set up IIS as a reverse proxy on a partial path in IIS. The point being is that multiple .net applications may want to host on port 80. If you only have a single application hosted on root, then yes, a libuv server is better.Delogu

© 2022 - 2024 — McMap. All rights reserved.