.NET 远程处理:无法连接到 Windows 服务中除 localhost 之外的远程对象?

发布于 2024-10-12 18:33:54 字数 701 浏览 0 评论 0原文

我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔戏命师 2024-10-19 18:33:54

尝试禁用 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

And after you've determined that the
port you're using is being blocked,
re-enable the firewall and create an
exception that allows connections on
that port.

(Thanks to Jim Mischel for his comment reminding us that this was necessary.)

梦屿孤独相伴 2024-10-19 18:33:54

如果您通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文