Monday, September 04, 2006

HttpListenerContext is not serializable

Today I started working on my own subclass of HttpWorkerRequest so that my webserver could handle POSTs and binary data like rails.png on the Welcome Aboard page. After writing all the code to handle the necessary overrides I went to actually run the thing and discovered the troubling fact in my subject line. HttpListenerContext is not serializable. Since my host runs in a separate AppDomain, this is a big problem.

I thought about trying to make some serializable dummy class to shuttle data back and forth, but then I came across Aaron Skonnard's Service Station article in MSDN Magazine here where he hit the same thing. His solution was just to move the HttpListener into the host's AppDomain, which is exactly the right thing to do. After doing that, everything works great. I successfully served the whole Rails Welcome Aboard page including the png (and the AJAX link for environment info), as well as a few test aspx pages with postbacks. There are still some rough edges (no default page handling, untested auth, etc.), but I think this is good enough to move on to working with a pool of Ruby processes for handling Rails.

2 comments:

mortench said...

Interesting work getting RoR to work on Windows! Do you have an email? I have a few things I would like to discuss with you off-line.... You can find my contact info at my homepage "www.mortench.net"

Anonymous said...

Moving HttpListener into AppDomain created in ApplicationHost class is really not a good idea. HttpRuntime.ProcessRequest can throw AppDomainUnloadException. Then you're basically stuck.