Use HttpListener for a production caliber web server?

camelCase picture camelCase · Aug 13, 2009 · Viewed 8.8k times · Source

Is it realistic to use the C# .Net class HttpListener as the foundation for a production caliber web server?

The http web service I need to host contains no .aspx or static files. All http responses are dynamic and generated in c# code that is invoked via a few switch statements which inspect a restful url format.

My thinking is that IIS is really a user-mode wrapper around the Windows o/s HTTP-SYS kernel module that does all the heavy duty network handling and so is HttpListener.

I already have a basic multithreaded web server running which is excellent for development because it starts in debug mode in an instance, now I am thinking do I need the overkill of IIS for production. A low memory footprint is another attraction.

Answer

Dave Markle picture Dave Markle · Aug 13, 2009

You have two serious choices here. And no, coding your own Web Server with HttpListener isn't production-grade.

1) Use IIS. It has a ton of features for security, performance, and perhaps more importantly, manageability, that you would have to reinvent yourself. Like remote administration, logging, integrated Windows Security, etc.

2) Use WCF and create a ServiceHost to host your files. Then you will have to implement your own services and find a way to manage their lifetimes. You can do it, but again, if you're talking RESTFul web calls, IIS really is the way to go.

Manually rolling your own should be avoided. IIS has changed a lot in the past 10 years. It's by no means a big monolithic server anymore. They've modularized just about everything, especially in Windows 2008, so you get a lean and fast system.