.NET 远程处理:无法连接到 Windows 服务中除 localhost 之外的远程对象?
我创建了一个 Window 服务,它在本地主机中运行良好。但是,当我将其安装到另一台计算机(使用我的帐户)时,另一台计算机上的客户端返回“无法连接到远程服务器”。如果客户端在同一台机器上运行,它就可以正常工作。我还尝试在控制台应用程序中托管相同的远程对象,并且它可以在远程计算机上正常工作。
这是我的服务的 OnStart() 中的代码:
HttpChannel channel = new HttpChannel(8080);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyService), "MyService", WellKnownObjectMode.Singleton);
这是客户端代码:
ChannelServices.RegisterChannel(new HttpChannel(), false);
MyService myService = (MyService)Activator.GetObject(typeof(MyService), "http://xxx.xxx.xxx.xxx:8080/MyService");
我发现有人在互联网上问过这个问题,但没有答案。有人知道线索吗?
I created a Window Service and it runs fine in localhost. However, when I install it into a different machine (using my account), my client on the other machine returns "Unable to connect to the remote server". If the client runs on the same machine, it just works fine. I also tried hosting the same remote object in Console app, and it works from remote machine without problem.
This is the code in my service's OnStart():
HttpChannel channel = new HttpChannel(8080);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyService), "MyService", WellKnownObjectMode.Singleton);
Here is the client code:
ChannelServices.RegisterChannel(new HttpChannel(), false);
MyService myService = (MyService)Activator.GetObject(typeof(MyService), "http://xxx.xxx.xxx.xxx:8080/MyService");
I found somebody asking this question before on Internet, but no answer. Anybody got clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试禁用 Windows 防火墙(或任何防火墙)。您尝试访问我们的端口可能被阻止。
重要更新
(感谢 Jim Mischel 的评论,提醒我们这是必要的。)
Try disabling Windows Firewall (or any firewall, for that matter). It might be that the port you're trying to us is blocked.
Important Update
(Thanks to Jim Mischel for his comment reminding us that this was necessary.)
如果您通过 Visual Studio 工作并使用其内部 Web 服务器,则它不接受来自外部 IP 地址的连接。它只接受本地主机连接。
If you're working through Visual Studio and using its internal web server, it doesn't accept connections from external IP addresses. It only accepts localhost connections.