Starting multiple HTTP listeners on IIS using C#.NET 2.0

Hari Das Kumaran picture Hari Das Kumaran · Oct 18, 2008 · Viewed 8.3k times · Source

I have two windows services running on the same machine. Both the services uses

private HttpListener listener;

I specify the baseURL as "http://IPAddress:8080/" & "http://IPAddress:8081/" respectively for each of the services. Then I do the needful and call

listener.Start();

The first service starts successfully at 8080 port. But when I now start the 2nd service, I get HTTPListenerException "The process cannot access the file because it is being used by another process" for listener object.

Could anybody please tell me: 1) If it is possible to start two HTTP listeners on the same IIS at two different ports. 2) If yes, how can we achecive this? 3) Is there any other way of doing this?

For your information: I am using C#.NET 2.0 and IIS 6.0 server.

Thanks & Regards,

Hari

Answer

splattne picture splattne · Oct 18, 2008

Doesn't HttpListener work independently from IIS? Can you stop the IIS service and see what happens?

Or maybe port 8081 is used by another program or process. I suggest to try to set the port to another number. You could open a command line and execute the "netstat" command to see if the port is used before starting your services.

alt text
(source: googlepages.com)