[英]Connecting two machines via internet using WCF
I have recently started studying WCF. 我最近开始学习WCF。 So I written a simple application.
所以我写了一个简单的应用程序。 Client sends a string and server just outputs it on the screen.
客户端发送一个字符串,服务器只在屏幕上输出它。 The app works fine on my computer with local address.
该应用在具有本地地址的计算机上可以正常运行。 But when i try to connect with my IP through internet, i get this exception:
但是,当我尝试通过Internet与IP连接时,会出现以下异常:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://(IP):4000/IContract that could accept the message.
System.ServiceModel.EndpointNotFoundException:在http://(IP):4000 / IContract上没有侦听终结点的端点可以接受该消息。
Port is open and available. 端口已打开并且可用。 Please tell me, what I am missing.
请告诉我,我想念的是什么。 here is how I declare address:
这是我声明地址的方式:
Uri adress = new Uri("http://(IP of computer, running server):4000/IContract");
I`ve taken my IP address from a website. 我已经从网站上获取了我的IP地址。 It gave me two of the.
它给了我两个。 My Ip address and my local IP address.
我的IP地址和本地IP地址。 So, local works only when client and server both on my PC.
因此,仅当客户端和服务器都在我的PC上时,本地才起作用。 When I try not local - nothing works at all.
当我尝试不本地操作时-根本没有任何效果。
Would appreciate any help. 将不胜感激。
Here is the code from Service provider: 这是来自服务提供商的代码:
Uri adress = new Uri("http://212.3.115.3:4000/IContract");
BasicHttpBinding binding = new BasicHttpBinding();
Type contract = typeof(IContract);
ServiceHost host = new ServiceHost(typeof(Service));
host.AddServiceEndpoint(contract,binding,adress);
host.Open();
Here is the code from Service consumer: 这是来自服务使用者的代码:
Uri adress = new Uri("http://212.3.115.3:4000/IContract");
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress(adress);
ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);
IContract channel = factory.CreateChannel();
channel.Say(tmp);
Ordered static IP for the machine, containing Service Provider. 为机器订购的静态IP,包含服务提供商。 And plugged Ethernet cable directly into PC.
并将以太网电缆直接插入PC。 It worked, so thanks, everybody.
它奏效了,所以谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.