Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

Well, as it was said - try to use IIS at first.

HttpListener is not bad at all - that's fastest managed listener server you can have now (faster than TcpListener and faster than Socket class). And it's actually the same core as with IIS. But IIS has a lot of more things.

I can't say IIS is monolith - hosting usage shown that it became worse in Win2008 in terms of stability and management. But your hand-made solution can be much worse. And also don't forget - http.sys much more customizable than HttpListener. I.e. you can't do streaming with HttpListener, but you can do that with http.sys - Question about HttpListener streaming

But if you will have enough power as a developer - you can try to write up own http.sys wrapper and that is best approach of writing own web server in Windows.

Rubbish, Roll your own. The architecture allows it. Be aware though there are some strange behaviours in the Class. Closing it down a couple of times in an NT service makes it flakey as a bag of puff pastries.

If you run it on Console, no problems whatsoever, run it async and all should be well, however, starting and stopping the darn thing. thats a different issue which I am currently struggling with as no errors are being produced from the hermetically Microsoft sealed classes.

I feel python coming on with a little dash of cherryPy

If you write it, then you'll have to maintain it. Microsoft has already written a web server - you should use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top