views:

1279

answers:

4

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.

+2  A: 

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

John Saunders
Memory consumption is a good reason not to use IIS. Last time I used it in anger we had to enable the 3GB switch to give IIS more memory headroom over 1.7Gb. Do the maths for hosting on a cloud platform and you'll see the $$$ problem.
I strongly suggest you try IIS 7 and see if this is still a problem. It may also have been due to the specific application, and not to IIS.
John Saunders
@JS "I strongly suggest you try IIS 7 and see if this is still a problem." Ok will do, I am on BizSpark now so I can fire up some MS test tools for a memory soak test. One gotcha, the Amazon cloud platform is stuck on Windows 2003 for the moment... ho hmm.
+3  A: 

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.

Dave Markle
@Dave Markle - Thanks I need to read up on IIS improvements, my knowledge stalled at Windows 2003. Lean and fast is what I need.
@Dave Markle - No remote admin = good one less config security hole. No logging = no problem, with dynamic web services much of the nature of the request is buried in the post data so logs don't expose much for diagnostics. No integrated security = good, don't need it so one less thing to misconfigure.
You're judging by the standards of Windows Server 2003. 2008-2003 = 5 years difference. The logging is much better, is not limited to the one-liners in the IIS log, and includes detailed failed request logging.
John Saunders
+2  A: 

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.

Mash
Do you have a URL that details how Win2008 declined in stability and management?
Dan Finch
+1  A: 

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

iestyn