views:

30

answers:

2

I'm writing a windows service which will expose an http RESTful web service for other processes on the machine. This will be deployed to lots of machines on various corporate desktops that I have little/no control over. How should I choose which port my service should listen on?

I'll make it configurable, but need to know how to choose some reasonable default(s).

fyi I'm planning on using .NET 3.5 (unable to use 4.0 for deployment reasons) and WCF with WCF REST Starter Toolkit.

UPDATE: to clarify, these are corporate non-development machines. I want to choose a port that's not likely to be used for anything else. I guess from this list of PORT NUMBERS (thanks @Pascal Thivent) that I should choose one in the dynamic/private range

The Dynamic and/or Private Ports are those from 49152 through 65535

So is there any better way of choosing a port within that range, or do I just choose randomly?

+1  A: 

If your service is HTTP then you should use port 80 - the standard HTTP port. This is typical of most REST webservices.

Dan Puzey
And if port 80 is taken, 8080 *et seq* are common alternatives.
Daniel Pryden
The service is running on a desktop machine. Port 80 isn't appropriate as I'm not providing a general-purpose web server and it's quite likely something else (e.g. skype) would be hogging that port already.
Rory
In that case, @Daniel's comment is relevant: 8080 and upwards. (And, btw, I hope my -1 wasn't for answering the question as originally posted...)
Dan Puzey
A: 

The official assignments registred with the Internet Assigned Numbers Authority (IANA) for HTTP are:

  • 80: standard port for HTTP,
  • 8080: HTTP alternate (commonly used by cache or proxy or web server running as a non-root user)

The ports below are non official ports (not registered with IANA) that are also used:

  • 8081: HTTP alternate
  • 8090: HTTP alternate (used as an alternative to port 8080)

I don't know what kind of machines you are targeting but if they include development machines, I would probably use 8090 to minimize possible conflicts.

References

Pascal Thivent
They are standard corporate desktop machines in a non-development office environment. I don't want to use a standard port but rather choose a port that's not likely to be used for anything else.
Rory