views:

1573

answers:

4

Hi,

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

+1  A: 
splattne
A: 

The HTTPListener is indeed not a part of the IIS. It's just C# code.

did you do it like this?

String[] prefixes = { "http://localhost:8280/", "http://localhost:8281/"};

HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8280/");
listener.Start();

1) If it is possible to start two HTTP listeners on the same IIS at two different ports.

Yes, it is. But listeners on the IIS is not made through code, it's through the IIS administration tool, so that's probably not what you're trying to do. IIS is seperate from the c# code you're attampting.

2) If yes, how can we achecive this?

  • Try some other portnumbers (like 58080 and 58081) and try replacing "IPAddress" with "localhost". Most likely your port number is used by some other webserver

3) Is there any other way of doing this?

If you're trying to serve webpages, you probably wan't to make a webapplication instead of making your own http server

If you're doing something custom, you might want to take a look at WCF (Windows Communication Foundation), as it's the new framework for web, sockets, webservices etc. and it's what MS will be using going forward

Sebastian
+1  A: 

Hi All,

Thanks for your immediate response :-)

Port number was the problem. I was using port numbers like 8080,8081,8082, etc,. Probably these ports were already being used.

I tried with ports http://localhost:8080 and http://localhost/35124 and it worked.

once again thanks for your responses.

Thanks & Regards,

Hari

+1  A: 

It's usually a good idea to take a quick look at this page when using port numbers...just to make sure a temp number you're trying to use isn't in use already.

Jonas