views:

277

answers:

5

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.

A: 

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 Stratton
+1  A: 

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.

+1  A: 

Hi, David.

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

Derek Schwartz
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
+3  A: 

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

Derek Schwartz
A: 

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...

David Thibault