tags:

views:

34

answers:

1

I need to redirect all requests on port 80 of an application server to a web server. I'm trying to avoid the need to install IIS and instead use WCF to do the job.

It looks like an operation such as the one below is suitable but one problem I've got is if a URL of the form http://mydomain.com/ is used then WCF will present a page about metadata.

    [OperationContract, WebGet(UriTemplate = "*")]
    RedirectToWebServer();

Does anybody know of a way to get WCF behaving the same as IIS in redirect mode?

+1  A: 

This just seems like the wrong tool for the job. If you really don't want to use one of the many web servers that could do this with a couple minutes of setup time (IIS, Apache, Lighttpd), you could just make a simple HTTP socket server.

Listen on port 80. As soon as you get two newlines in a row, send back the response:

HTTP/1.1 301 Moved Permanently
Location: http://myothersite.com/whatever

(I'm almost certain that's the minimum you need). If you want to be really fancy and follow HTTP specs, match HTTP/1.1 or HTTP/1.0 based on what the request has.. but for a quick and dirty redirect, that's all you need.

That said, again, I'd say go grab another web server and set up a redirect using it. There are many lightweight HTTP servers that will work.

gregmac