Web service outside IIS

Posted: August 16, 2008 in Computer and Internet

 

Theoretically this is easy, simply host ASP.Net in your process and plug a HTTP handler in front of it. Practically I had plenty of problems.

First I simply tried to do CreateApplicationHost and host ASP.Net inside that with my own proxy handler. This worked nicely, once I figured out that ASP.Net requires you to put your assemblies in the bin directory relative your working directory. I used the HttpListener (http.sys in the kernel) to handle the HTTP protocol for me. Unfortunately the HttpListener (the problem was I thought it was CreateApplicationHost that caused the problem was led me off track for quite some time) requires admin rights because it supports port sharing. (That is you can have several service listening in on port 80 with different prefixed, very useful), so even if this worked I did not like that I had to run as admin so I moved on to the next step as I read that a WCF service can expose itself as an ASMX compatible service and I thought it was time to move closer to the present and dig into WCF.

I tried to self host a WCF service and expose it as a basic HTTP service type. This led me to some problems with how wsdl was produced. Then I tried to instead dual host the WCF service as WCF and ASMX service by simply adding WebService, WebMethod respectively. This sort of worked but was still tricky.

So I decided to see if I could find a way to use HttpListener without admin rights or if there was a replacement (Cassini for instance). I finally entered the correct magic words into Google and it give me a solution after several attempts which led nowhere.

httpcfg to the rescue and you get the sources to it too!

http://msdn.microsoft.com/en-us/library/aa364478(VS.85).aspx

http://www.oreillynet.com/windows/blog/2005/09/httplistener_and_nonadmin.html

This also led me to the article how all this ASP.Net hosting works, too bad I didn’t read that before I started all this

http://msdn.microsoft.com/sv-se/magazine/cc163879(en-us).aspx

I would like to use WCF in the end, but I was very happy when I learned about httpcfg that I wanted to record it here.

I might post fully working samples later on.

http://blogs.msdn.com/mattavis/archive/2005/10/10/479280.aspx

http://msdn.microsoft.com/en-us/magazine/cc163357.aspx

http://kjellsj.blogspot.com/2006/12/how-to-expose-wcf-service-also-as-asmx.html

Finally I wanted to consume this web service from a classic ASP page (mostly for fun)

http://bytes.com/forum/thread55472.html

http://www.4guysfromrolla.com/webtech/070302-1.shtml

WCF looks like a very promising solution and finally making it easy to host anything in any form (either inside IIS or outside in your own app, or in a web farm)

I will see about posting some sample code

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s