问题
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>
The BindingConfiguration and behaviorConfiguration are very simple, just configuring some timeouts.
In my exe, I start the host like this.
_serverHost = new ServiceHost(type); // implementing IClientCommand
_serverHost.Open();
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.
But I don't get why it goes from localhost to "0.0.0.0"?
回答1:
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.
来源:https://stackoverflow.com/questions/15428610/wcf-service-endpoint-localhost-confusion