我已经实现了一个简单的聊天控制台应用程序,它运行良好。当我试图在GUI应用程序上应用相同的概念时。服务端托管时,有任何错误,但如果我使用CMD命令netstat -ao显示所有端口,它不存在。因此,当我运行客户端应用程序,有一个例外(无法连接,因为目标机器积极拒绝)。我如何解决这些问题?WCF服务不在机器上
服务器
ServiceHost host;
using (host = new ServiceHost(typeof(Service), new Uri("net.tcp://localhost:4111")))
{
host.AddServiceEndpoint(typeof(IService), new NetTcpBinding(), "IService");
try
{
host.Open();
}
catch
{
}
}
客户
public bool Connect()
{
DuplexChannelFactory<IService> pipeFactory = new DuplexChannelFactory<IService>(new InstanceContext(this),
new NetTcpBinding(),
new EndpointAddress(AppConfiguration.GetValue(net.tcp://localhost:4111/IService"));
try
{
pipeProxy = pipeFactory.CreateChannel();
if (pipeProxy.Register())
{
return true;
}
}
catch
{
}
return false;
}
您是否试图从与服务器相同的计算机运行客户端?如果没有,'net.tcp:// localhost:4111'会出现问题。 – 2012-02-05 01:08:28