WCF中localhost和127.0.0.1绑定的区别
NetTcpBinding binding = new NetTcpBinding();
string address = "net.tcp://localhost:9999/HelloWorld";
using (ServiceHost host = new ServiceHost(typeof(HelloWorldClass)))
{
host.AddServiceEndpoint(typeof(IHelloWorld), binding, address);
Console.WriteLine("正在启动服务……");
host.Open();
Console.WriteLine("服务启动完成……");
Console.WriteLine(binding.PortSharingEnabled);
Console.WriteLine("按任意键结束");
Console.Read();
}
上面的代码完成NetTcpBinding,当地址使用localhost时,程序运行通过命令netstat -a查看,绑定的本地地址是0.0.0.0:9999,当使用127.0.0.1时,使用netstat -a查看绑定的本地地址是127.0.0.1:9999。在.net wcf绑定中,localhost和127.0.0.1到底有什么区别和联系?