简体   繁体   English

在部署窗口服务托管的WCF服务时如何管理端口号

[英]how to manage port number in deploying a window service hosted WCF service

Sorry if this sounds very simple but I am very new to wcf/network so please bear with me. 抱歉,这听起来很简单,但我对wcf / networking还是陌生的,所以请多多包涵。

I want to deploy a window service hosted WCF service to three servers (Dev, UAT, Prod) hence the endpoint url for each server needs to be stored in database so that deployment can be automated using a script. 我想将窗口服务托管的WCF服务部署到三台服务器(Dev,UAT,Prod),因此每台服务器的端点url需要存储在数据库中,以便可以使用脚本自动进行部署。 The window service does nothing but hosting the wcf service and when it starts, I set the endpoint url to be localhost:8081/MyCompnay/MyService and simply use a default BasicHttpBinding to pass into the service host constructor. 窗口服务除了托管wcf服务外什么也不做,当它启动时,我将端点URL设置为localhost:8081 / MyCompnay / MyService,并仅使用默认的BasicHttpBinding传递给服务主机构造函数。 I am currently choosing a random port number (8080 is almost for sure in use already), I wonder what's the optimal way of managing port number in such a case that the service will be deployed to different servers? 我当前正在选择一个随机端口号(几乎肯定已经使用8080),我想知道在将服务部署到不同服务器的情况下管理端口号的最佳方法是什么? I am concerned that even if I make the port number configurable, it could happen that the same port number might be taken by some other applications when my service is restarted after a shutdown (for whatever reason!). 我担心即使我将端口号设置为可配置的,也可能发生以下情况:在关闭后重新启动我的服务时,某些其他应用程序可能会使用相同的端口号(无论出于何种原因!)。 I want to be sure that the port number I set won't be taken by other applications. 我想确保我设置的端口号不会被其他应用程序占用。 Hope I have made this clear. 希望我已经说清楚了。

There is never a guarantee that the port number will not be taken. 永远不能保证不会占用该端口号。 You could have a series of port numbers that you try and work your way through them until you find one that works. 您可以尝试使用一系列端口号,直到找到有效的端口号为止。 If you don't find one that works then you error out and inform the user. 如果找不到有效的方法,则会出错并通知用户。 Choose port numbers above 49151 as these are considered private ports . 选择高于49151的端口号,因为它们被视为专用端口

If you don't need the HTTP binding, you could use a Named Pipe binding that doesn't require a port, but there are different limitations to using that as well. 如果不需要HTTP绑定,则可以使用不需要端口的命名管道绑定,但是使用它也有不同的限制。

There is also the option of registering your port number with the IANA and then anyone using your port is technically the bad app, but there is no preventing it. 还可以选择在IANA上注册您的端口号,然后从技术上讲,使用您端口的任何人都是不好的应用程序,但是并不能阻止它。 This is overkill for a good majority of applications. 对于大多数应用程序来说,这是多余的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM