如何在构建Windows服务时选择使用哪个端口? (windows& .net) [英] How to choose which port to use when building a windows service? (windows & .net)

查看:108
本文介绍了如何在构建Windows服务时选择使用哪个端口? (windows& .net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Windows服务,它将为计算机上的其他进程公开一个http RESTful Web服务。这将被部署到我几乎无法控制的各种企业桌面上的许多机器上。我应该如何选择我的服务应该监听哪个端口?

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我打算使用.NET 3.5(出于部署原因无法使用4.0)和使用的WCF WCF REST入门工具包

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

更新:澄清一下,这些是企业非开发机器。我想选择一个不太可能用于其他任何东西的端口。我猜这个 PORT NUMBERS 列表(感谢@Pascal Thivent)我应该选择一个在动态/私人范围内

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


动态和/或私人端口是49152到65535的那些

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?

推荐答案

最终,我们在注册端口范围内选择了一个任意未使用的端口 - 从1024到49151 - 然后在有人出现的情况下对其进行配置,并使用该端口进行其他操作。那么最好的解决方案是注册该端口。

Ultimately we chose an arbitrary unused port in the Registered Port range - from 1024 through 49151 - and then made it configurable on the offchance someone comes along and uses that port for something else. Best solution would then be to register that port.

我们选择不使用动态端口,因为进程可以任意开始使用它们,因此无论端口是否可用,它都不太一致。

We chose not to use a dynamic port as processes are able to arbitrarily start using them, so it'd be less consistent whether the port was available.

这篇关于如何在构建Windows服务时选择使用哪个端口? (windows& .net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆