views:

972

answers:

3

I could run a Windows Service hosted WCF service listening http://localhost:80/MyService while IIS was serving pages on http://localhost:80 and both works.

But many places in the internet (like this and this) say that only a single process can listen each port simultaneoulsy.

Are they wrong?

+2  A: 

No. Only one process can bind to a port on an address at any one time. You can bind two processes to the same port number, but on different IP addresses, hence different ports.

From the above it looks like you need some form of request forwarding service listening on port 80, and depending on the URL requested, forward the request to either of your two processes which will be listening on different ports (e.g. 8080 and 8090)

EDIT: From re-interpreting your question and your comment, if both URLs are working, then something is forwarding requests. Possibly a 3rd process, but more likely one process is forwarding to another. To reiterate, though, only one process can listen to a port.

Brian Agnew
I am talking about something that is happening right now, are you implying that Windows somehow has this request forwarding service running without me asking it to do this?
Jader Dias
See my edit. If stuff is working, then I suspect one process is forwarding to the other
Brian Agnew
There IS a request forwarding service in Windows (WS2003 and later, Vista and later). It is called HTTP.sys. And it specifically is designed to do what Jader is doing. See my answer http://stackoverflow.com/questions/2067830/how-can-a-wcf-service-listen-the-same-port-as-iis/2068052#2068052
Cheeso
While this answer is factual, it is not correct.
jmucchiello
+1  A: 

Could it be that you are hosting the WCF service in IIS. So that IIS is sending the request to the WCF service based on the URL.

Edit: It may be also that the WCF services were setup to do port sharing like this: http://msdn.microsoft.com/en-us/library/ms734772.aspx

Edit2: Ok, I reread your edited question, see the links in this answer: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8993f7c5-1f78-4156-a131-d9b40af10d9a

"The IP Listen List allows WCF services to coexist with applications that use a port for some of the IP addresses of the machine. If the IP Listen List contains any entries, the HTTP Server API will only bind to those IP addresses that the list specifies."

AaronLS
Nope, I am hosting the WCF service as a Windows Service, it has it's own PID.
Jader Dias
Edited the question to clarify
Jader Dias
+6  A: 

HTTP.sys makes this possible. From the article:

...because WCF and IIS 6.0 both use the kernel-mode HTTP stack (HTTP.sys), IIS 6.0 can share port 80 with other self-hosted WCF services running on the same machine...

HTTP.sys acts as a port-forwarding service, for HTTP (port 80) traffic.

Cheeso
This is the answer. HTTP.sys is how multiple programs can listen on port 80 under Windows.
jmucchiello
and it also happens with other ports and protocols? http://stackoverflow.com/questions/2085790/can-2-wcf-service-processes-listen-the-same-port
Jader Dias