.NET2.0 Remoting - 为什么需要注册 ClientChannel?
我有一个必须使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该通道用于通信。 你通过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