2014-04-02 79 views
0

我在做应用程序内聊天的实现,所以我发现非常有用的文章由 作者:Ger Hayden(初学者指南Duplex WCF)。 下面的文章,我的聊天开始工作非常快(服务器和客户端在同一台PC上) 一切都很好,直到我在测试机器上部署聊天服务器。 在服务器端实现当WCF System.Diagnostics程序,我发现:WCF回调(客户端不在DNS)没有端点侦听..(求助)

Remote name could not be resolved

问题是,我的PC(客户端)又名a2200492.m022不在DNS中,因此服务器无法创建高分辨率计算机名称 - > IP。 我正在寻找解决方案来配置WCF使用IP而不是计算机名称,但我没有找到这样的配置参数。 (如果有人请让我知道) 接下来我从有类似问题的人,想将PC添加到DNS,或添加到服务器主机文件的想法。但我想要一般解决方案。 所以,这工作溶液(或更好的解决方法)是(从后面的代码把当前客户端IP): 客户端代码:

//In method for connecting... 

System.ServiceModel.Channels.Binding b = new WSDualHttpBinding("WSDualHttpBinding_Server"); 
string clientID = Guid.NewGuid().ToString().Replace("-", ""); //if 2 app on same IP 
///////////////////////////////////////// 
//here is line that solved my problem, let server make callback to my ip 
(b as WSDualHttpBinding).ClientBaseAddress = new Uri(@"http://" + MyIp() + "/" + clientID);** 
///////////////////////////////////////// 
(b as WSDualHttpBinding).ReliableSession = new ReliableSession(){Ordered=true}; 
(b as WSDualHttpBinding).Security = new WSDualHttpSecurity() { Mode = WSDualHttpSecurityMode.None }; 
(b as WSDualHttpBinding).HostNameComparisonMode = HostNameComparisonMode.WeakWildcard; 

//ServerIP 
EndpointAddress serverIp = new EndpointAddress(System.Configuration.ConfigurationManager.AppSettings["ChatServer"].ToString()); 

//Instantiate service reference 
chatServer = new ChatServerRef.ServerClient(new InstanceContext(this), b, serverIp); 
//Next step is call method JoinTheConversation on chatServer 

回答

0

在运行时

改变ClientBaseAddress解决