10

I'm looking for a way to host a web UI in a windows service so that I can configure and control it within a browser. I'd like a simple and lightweight solution, and I don't want to use IIS.

I could probably hand-roll most of it but I was wondering if there was something already made to ease the process.

YakovL
  • 7,557
  • 12
  • 62
  • 102
David Thibault
  • 8,638
  • 3
  • 37
  • 51

7 Answers7

3

Here's another option if you want an embedded server, but not a service or any external HTML/ASPX files:

WebConfig - your wireless router has it, now you can too http://www.codeproject.com/KB/game/WebConfig.aspx

2

I've been wanting to do the exact same thing with a windows service that I created. I may have finally found an article that will help. I haven't tried this yet, but I think it has the base of what we both need -- along with sample source.

The focus of the article is on how to host a web service (ASMX) from within your code, but I assume that it could just as easily host an ASPX page.

http://msdn.microsoft.com/en-us/magazine/cc163879.aspx

-Derek

  • Thank you for your response. I already looked at System.Web.Hosting (actually, I looked at Cassini), and found it a bit complex for my needs. I don't really need to host aspx pages, I just want to be able to respond to incoming requests with code. I have actually started working on a project that does just that, using System.Net.HttpListener. I plan on making it available as open source when I have a first version. I'll add an answer to this question when I do. – David Thibault Oct 28 '09 at 01:13
1

You could always use WCF to host an endpoint within the service and expose it that way.

The only other options I can think of would involve having some file that a web app could write to and the service could read from, or a database that's written to by the web site and read from the service. None of those are as elegant as simply exposing a communication endpoint via WCF.

Edit - Added

Specifically, I was thinking of exposing this as an HTTP endpoint and interfacing directly with the browser the way you would a web service.

However, there's no reason you couldn't have a traditional Asp.Net application set up to communicate with the service as long as the service hosts a communication endpoint.

David
  • 72,686
  • 18
  • 132
  • 173
  • +1 I think this is the cleanest approach, especially above hosting an in-process web server. I use WCF like this. It allows you to cleanly architect the solution by separating concerns. The WCF service exposes an API but stays UI independent. Maybe we expose as a web page today, but tomorrow we also offer a desktop tool. – codenheim Dec 19 '15 at 20:10
1

If you are looking at UI instead of a web service interface there are a couple of things you could do:

1) It may be more than you need but you could host ASP.NET in your service using the original Cassini code base: http://blogs.msdn.com/dmitryr/archive/2005/09/27/474534.aspx

2) You could also just open a port, and put a simple HTML page on separate thread(s) in your service depending on how much you expect the service to be accessed.

I have done both of these a few times, and either one is pretty straightforward as long as you don't care about security - e.g. the machine is only accessible from a trusted intranet. If that is not the case you are better off hosting IIS on the machine and writing a secure web app.

jnoss
  • 2,049
  • 1
  • 17
  • 20
1

Edit: Please don't use this. It was a simple proof of concept and I never went anywhere with it. Please see my other answer for better solutions.


Well, better late than never. Didn't have much time to work on it.

http://github.com/leddt/SimpleHttpServer

This is extremely basic stuff, and not intended for production use. It's a small project I'm experimenting with. I will however take comments, suggestions etc...

Community
  • 1
  • 1
David Thibault
  • 8,638
  • 3
  • 37
  • 51
1

Since this question was originally posted, much better solutions to the problem have been released.

If you are targeting .Net Core, it is trivial to self-host ASP.Net Core by using the WebHostBuilder.

Another solution is Nancy, which is also easy to self-host.

David Thibault
  • 8,638
  • 3
  • 37
  • 51
  • I have same requirement. Could you help here https://stackoverflow.com/questions/55628101/page-is-not-loading-when-host-asp-net-core-in-a-windows-service – kudlatiger Apr 11 '19 at 08:39
0

The focus of the article is on how to host a web service (ASMX) from within your code, but I assume that it could just as easily host an ASPX page.

http://msdn.microsoft.com/en-us/magazine/cc163879.aspx

Kanwar Singh
  • 908
  • 12
  • 21