.NET2.0 Remoting - 为什么需要注册 ClientChannel?

发布于 2024-07-09 15:40:45 字数 1065 浏览 2 评论 0原文

我有一个必须使用 .NET Remoting 的客户端/服务器应用程序(不是 WCF,因为该项目使用的是 Framework 2)。

下面的代码(大量从 MSDN 复制)可以工作:

                _clientChannel = new IpcClientChannel();

                ChannelServices.RegisterChannel(_clientChannel, false);

                IMyObject myObject= (IMyObject)
                        Activator.GetObject(typeof(IMyObject),
                        "ipc://MyServer/Address");

                if ( myObject.Equals(null) )
                    Console.WriteLine("Error: unable to locate server.");
                else
                    returnString = myObject.SomeMethod();

                ChannelServices.UnregisterChannel(_clientChannel);

但这三行是做什么的呢?

                    _clientChannel = new IpcClientChannel();

                    ChannelServices.RegisterChannel(_clientChannel, false);

                    ...

                    ChannelServices.UnregisterChannel(_clientChannel);

_clientChannel 之后不会在工作代码中的任何地方使用。 工作代码似乎在没有这三行的情况下也可以工作。 我可以在不失去功能的情况下摆脱它们吗?

I have a client/server application that must use .NET Remoting (not WCF because the project is using Framework 2).

The following code (copied heavily from MSDN) works:

                _clientChannel = new IpcClientChannel();

                ChannelServices.RegisterChannel(_clientChannel, false);

                IMyObject myObject= (IMyObject)
                        Activator.GetObject(typeof(IMyObject),
                        "ipc://MyServer/Address");

                if ( myObject.Equals(null) )
                    Console.WriteLine("Error: unable to locate server.");
                else
                    returnString = myObject.SomeMethod();

                ChannelServices.UnregisterChannel(_clientChannel);

But what do these three lines do?

                    _clientChannel = new IpcClientChannel();

                    ChannelServices.RegisterChannel(_clientChannel, false);

                    ...

                    ChannelServices.UnregisterChannel(_clientChannel);

_clientChannel doesn't get used anywhere afterwards in the working code. The working code also seems to work without those three lines. Can I get rid of them without losing functionality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

天冷不及心凉 2024-07-16 15:40:45

该通道用于通信。 你通过Activator得到的Object只是一个代理对象,隐藏了真正的实现并使用通道进行通信。

有关远程处理的更多信息,请参阅 MSDN

The channel is used for the communication. The Object you get through the Activator is only a proxy objects that hides the real implementation and uses the channel for communication.

See MSDN for further information on remoting

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