0

I am interested in making a web front end for my C# Console Application (it is ran on dedicated machines as a service so the user never sees the console) allowing for control of various features. I have very little experience with ASP.net so I need to find out what the best approach would be for this.

Right now I have embedded this nice little web server into it (http://webserver.codeplex.com) but I imagine doing a front-end with ASP.net would give a lot more control over the application. I have had very little luck with Google results as most of the searches pertain to ASP.net or Console Applications, but not using them together. I basically need to not only pull information from my application and display it, but allow user input as well (mostly just text boxes and buttons).

The other problem I ran into was it doesn't seem like any good solutions exist for embedding an ASP.net web server. I found UltiDev Cassini and aspNETServe but neither seems like it can be embedded. Both look like they require additional software to be running, which is difficult since I just want to distribute a .exe file. Is it not possible to completely embed a ASP.net server?

  • is this a "service" meaning it's constantly on taking requests? – Dustin Davis Aug 24 '11 at 21:05
  • You can't embed a web server; that concept kinda has no meaning. In effect, you're asking if you can distribute an EXE with an embedded web application? – Tejs Aug 24 '11 at 21:07
  • @Dustin - Yeah, my application manages another application that runs 24/7 so it is always on –  Aug 24 '11 at 21:08
  • @Tejs - I am not sure what you mean by you can't embed a web server, as that is exactly what webserver.codeplex.com is. But yes, part of the question is can an ASP.net web server be embedded into an EXE? –  Aug 24 '11 at 21:09
  • If your console app is taking input, maybe over http/tcp or msmq, then just start by add some buttons to an asp.net site and send that particular message to your app (or message queue). Helps if it's all on the same network. You can host your asp.net site in IIS, IIS Express or any other applicable web server (cassini, apache) – Dustin Davis Aug 24 '11 at 21:09
  • That is my point of confusion really, as I don't understand exactly how I passthe input from the asp.net site to my application. Also, I just found XSP which appears to be an embedded ASP.net web server, but it is for Mono. http://www.mono-project.com/ASP.NET#ASP.NET_hosting_with_XSP –  Aug 24 '11 at 21:12
  • 1
    In your situation, I would consider a general refactoring to an actual Windows Service. That way you can have your code running as you please, but also provide a UI to show when you need to change settings. – Tejs Aug 24 '11 at 21:13
  • You just have a console app that waits for a user to press a key? I this @Tejs is on the right track, you need to rethink your architecture. – Dustin Davis Aug 24 '11 at 21:44
  • No, as of right now my application has no physical input. It launches and manages another application, has a tcp/udp servers built into it using a game related protocol, and some other various features. I would just like to add some control over it using a web-interface. –  Aug 24 '11 at 22:05

1 Answers1

0

You may want to look at IIS Hosted Web Core (HWC), which allows you to embed the core of IIS inside your application. I believe it can serve up ASPX files. In the spirit of full disclosure, I have not used HWC, so I can't say whether it will do what you want. But I've been interested in it since Azure uses (used?) HWC for it's web roles in earlier versions.

But from I've read, I think it can do what you want. The drawback is that I think it requires you to do some native (C++) programming. Not sure if that helps or not, but I think this is going to be pretty close to what you're looking for.

Here's a blog article describing how to embed HWC in a Console Application.

Hope this helps!

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
  • This is extremely helpful, thank you. My main question though, which I am still having a problem finding an answer to is, how difficult is it to interact with a console application from a web interface? Whether I use a basic embeded web-server (just html) or ASPX, I am having trouble figuring out how I should be using it to interact with my console application. For the most part the data will just be going out from my application to the web page, but in some instances I want them to be able to...lets say stop the application by clicking a button. –  Aug 25 '11 at 01:14
  • I don't see why you can't interact with the console app from the web app. So let's say the web app has a button that says 'STOP'. You click it and it sends a POST to a method in your console app (StopServer). In StopServer, you could just call Application.Exit(). Getting information back to your client may be tough, but I don't see why you can't do that. – David Hoerster Aug 25 '11 at 01:25
  • And if that's what you're looking to do, and not just serve ASPX pages, look at the lightweight servers out there like Nancy (https://github.com/thecodejunkie/Nancy). Simple language to describe your methods and you can easily host it in a console app without the hassles of what you'd have to do with HWC. – David Hoerster Aug 25 '11 at 01:26
  • David, this looks absolutely fantastic. This is somewhat of a solution I had no idea existed, but looks perfect for my needs. I am having trouble finding any sort of documentation or tutorials for this framework though. Do you know if any exist that I am missing or any alternatives to Nancy? –  Aug 25 '11 at 01:42
  • Disregard, completely missed the wiki (getting fragile in my old age). Thank you very much! –  Aug 25 '11 at 01:44
  • No problem Brett. I hope it works out for you. Nancy caught my eye (that sounds bad) a few months back and I've been meaning to put an app together with it. It looks very simple and yet powerful. Good luck!! – David Hoerster Aug 25 '11 at 01:50