views:

46

answers:

2

I have a .NET 4 application that runs as a windows service. It runs periodic tasks and provides WCF restful webservices. It already hosts a silverlight web page (via WCF) that allows a user to configure the service.

Now I have a requirement to provide information on HTML/java script pages (e.g. for browsers and platforms that don't support Silverlight). I can serve simple HTML and javascript pages through WCF but that becomes laborious very quickly. I'd like to use MVC2.

Is it possible to provide MVC2 web pages from within a windows service? Or at least use some of the functionality provided by MVC like routing and the view engine?

Or is it more trouble than it's worth and should I head down the path of a separate app hosted on IIS?

A: 

You can host the ASP.NET runtime in any type of application including a Windows Service using the CreateApplicationHost method. Although note that by doing this you lose the robustness, security, logging, etc... that a real web server such as IIS provides.

Darin Dimitrov
Thanks. That's what I was looking for.Right now the application is a nice self contained windows service and it would be nice to keep it like that. It already has logging and security and should be as robust as IIS. So right now there's no reason to move it to IIS.I'll have a play and see how it goes. If an issue does arise that makes IIS the better option I'll head down that path.Thanks.
Smiffy
A: 

Since you're asking the question about what route to take, I'd host an MVC2 application in IIS. Why recreate a web server using WCF when IIS is already there - and since you're asking, it sounds like that's a viable option.

I agree with Darin's answer that you can host ASP.NET MVC2 in any application, but I think you're going to end up recreating a lot of plumbing that's already in place with IIS.

On the upside, if you go with serving up ASP.NET MVC2 resources in a WCF service application, it may end up rocking and you could have a nice application you can sell on the side. :)

David Hoerster