那里
上下文: 我编写了一个演示控制台应用程序 - 一个在 Linux 上通过 mono 运行的 WCF 服务,以及一个在 Windows 7 上运行的控制台客户端。
Linux Versoin:Ubuntu 和 Match-box
单声道版本:2.10.8.1(在 Ubuntu 上)和 2.10.6(在火柴盒上)
问题: 客户端可以通过 basicHttpBinding而不是netTcpBinding 与 Service 通信。
异常信息: 无法连接到 net.tcp://192.168.1.220/。连接尝试持续了 00:00:14.0408031 的时间跨度。TCP错误码10060:连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应192.168.1.220:808。
服务代码:
class Program
{
static void Main(string[] args)
{
try
{
ServiceHost sh = new ServiceHost(typeof(DynIPService.DynIPService));
//sh.AddServiceEndpoint("DynIPServiceContract.IDynIPService", binding, "net.tcp://10.161.66.213:808");
sh.Open();
foreach (var ep in sh.Description.Endpoints)
{
Console.WriteLine("Address: {0}, ListenUri: {1}, ListenUriMode: {2} ", ep.Address, ep.ListenUri, ep.ListenUriMode);
}
Console.WriteLine("Service is running");
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
throw;
}
finally
{
Console.ReadKey();
}
}
}
服务 app.config(部分,这里我只列出端点和绑定)
<services>
<service name="DynIPService.DynIPService" behaviorConfiguration="MyServiceTypeBehaviors" >
<endpoint address="net.tcp://127.0.0.1:808"
binding="netTcpBinding" bindingConfiguration="TCP_Binding"
contract="DynIPServiceContract.IDynIPService"/>
<endpoint address="http://127.0.0.1:123"
binding="basicHttpBinding" bindingConfiguration="HTTP_Binding"
contract="DynIPServiceContract.IDynIPService"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="HTTP_Binding">
<security mode="None"></security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="TCP_Binding">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
客户代码:
class Program
{
static void Main(string[] args)
{
//var ip = "localhost.localdomain";
var ip = "192.168.1.220";
//Tcp
Binding tcpBinding = new NetTcpBinding(SecurityMode.None);
var tcpUri = new Uri(string.Format("net.tcp://{0}:808", ip));
//http
Binding httpBinding = new BasicHttpBinding();
var httpUri = new Uri(string.Format("http://{0}:123",ip));
EndpointAddress address = new EndpointAddress(httpUri.ToString());
IDynIPService proxy = ChannelFactory<IDynIPService>.CreateChannel(httpBinding, address);
var hostIP = proxy.ReadHostIp();
Console.WriteLine(hostIP);
Console.ReadKey();
}
}