简体   繁体   English

使用WCF通过互联网连接两台机器

[英]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.

相关问题 使用wsDualHttpBinding超时通过Internet连接到WCF服务 - Connecting over internet to WCF service using wsDualHttpBinding times out 在Internet上的机器上设置WCF(或替代)Controller-worker - WCF (or alternative) Controller-worker setup on machines across the internet 通过Internet连接MySQL和.net应用程序有危险吗? - Is connecting MySQL and .net application via Internet a hazard? 通过NetNamedPipeBinding连接到WCF服务时出现问题 - Problems connecting to WCF Service via NetNamedPipeBinding Silverlight 5通过SSL连接到WCF服务 - Silverlight 5 connecting to WCF service via ssl 如何使用WCF C#通过Internet传输对象p2p - How to transfer an object p2p via internet using WCF C# 内部WCF的体系结构调用其哑巴DMZ版本连接到Internet - Architecture for Internal WCF calling its dumb DMZ version connecting to the Internet 使用wshttpbinding通过Internet消耗WCF服务吗? - Consume WCF service over the internet using wshttpbinding? 使用 WCF 将 SQL Azure 连接到 Windows Phone 7 - Connecting SQL Azure to Windows Phone 7 using WCF 通过BHO从outlook拖放到Internet Explorer可以在x32 / 86机器上运行 - Drag/drop from outlook to internet explorer via BHO doesn't work on x32/86 machines
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM