WCF服务端点localhost混乱 [英] WCF service endpoint localhost confusion
问题描述
我对为什么有些东西感到困惑.我正在像这样配置wcf服务:
I'm confused as to why something works. I'm configuring a wcf service like this:
<services>
<service name="ClientCommand" behaviorConfiguration="SomeServiceBehavior">
<endpoint contract="IClientCommand" binding="netTcpBinding" BindingConfiguration="TcpPort" address="net.tcp://localhost:1304" />
</service>
</services>
BindingConfiguration和behaviorConfiguration非常简单,只需配置一些超时即可.
The BindingConfiguration and behaviorConfiguration are very simple, just configuring some timeouts.
在我的exe中,我像这样启动主机.
In my exe, I start the host like this.
_serverHost = new ServiceHost(type); // implementing IClientCommand
_serverHost.Open();
这一切都非常简单并且可以正常工作,我可以从另一台PC上调用此服务.但是,在阅读了一个不同的问题(在tcp套接字上聆听)后,我得到的印象是它不起作用.当我绑定到 localhost 时,应该不能从正在其上运行的PC外部访问该服务?
我检查了PC上的netstat,它确实绑定到IP地址"0.0.0.0"而不是"127.0.0.1",解释了为什么它可以在另一台PC上工作.
It's all pretty simple and it works, I can call this service from a different pc. However, after reading up on a different issue (listening on tcp sockets), I get the impression it shouldn't work. As I'm binding to localhost the service should not be accessible from outside the pc it's running on?
I checked netstat on the pc and it did bind to ip address "0.0.0.0" instead of "127.0.0.1" explaining why it works from another pc.
但是我不明白为什么它从本地主机转到"0.0.0.0"?
But I don't get why it goes from localhost to "0.0.0.0"?
推荐答案
Net.tcp不仅限于在一台计算机上进行通信,也许您正在考虑使用net.pipe?关于0.0.0.0:如何在运行服务的计算机上定义主机文件? 此处是有关WCF的不错的文章.
Net.tcp is not restricted to communication on one machine, perhaps you are thinking on net.pipe? Regarding 0.0.0.0: How is the host file defined on the machine running the service? Here is a nice article on WCF in general.
这篇关于WCF服务端点localhost混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!