简体   繁体   English

使用WCF双工绑定时在客户端自动设置端口号

[英]Automatically set port number at client side while using wcf duplex binding

I have implemented wcf service with duplex binding and it is working fine. 我已经用双工绑定实现了wcf服务,并且工作正常。 What I have done at client side is I have configured ClientBaseAddress in config file. 在客户端执行的操作是在配置文件中配置了ClientBaseAddress。 Default port ie 80 which I want my application to automatically use available port. 默认端口,即80,我希望我的应用程序自动使用可用端口。

So my question, is there any way where I can automatically set the available free port? 所以我的问题是,有什么方法可以自动设置可用的空闲端口?

I'm not totally clear on what you are asking but as indicated in this answer, you can set the port to '0' and this will cause WCF to pick the next available free port. 我不清楚您要问的是什么,但是如答案所示,您可以将端口设置为“ 0”,这将导致WCF选择下一个可用的空闲端口。 However, this seems to be a random port and not necessarily port 80. It's unclear to me whether you specifically want port 80. 但是,这似乎是一个随机端口,并不一定是端口80。对我来说,不清楚您是否特别想要端口80。

Using this method will cause a problem on your client. 使用此方法会在您的客户端上引起问题。 They will not know which port to talk over. 他们将不知道要与哪个端口进行通话。 There is a feature in WCF called WCF Discovery in which a client 'discovers' the location of the service over a network. WCF中有一个称为WCF发现的功能 ,其中客户端通过网络“发现”服务的位置。

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

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