C# 连接到 .NET 远程服务器对象的最简单方法是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the simplest way to connect to a .NET remote server object
提问by nickd
Given that my client code knows everything it needs to about the remoting object, what's the simplest way to connect to it?
鉴于我的客户端代码知道它需要的关于远程对象的一切,连接到它的最简单方法是什么?
This is what I'm doing at the moment:
这就是我目前正在做的事情:
ChannelServices.RegisterChannel(new HttpChannel(), false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(IRemoteServer), "RemoteServer.rem", WellKnownObjectMode.Singleton);
MyServerObject = (IRemoteServer)Activator.GetObject(
typeof(IRemoteServer),
String.Format("tcp://{0}:{1}/RemoteServer.rem", server, port));
采纳答案by Ishmaeel
The first two lines are in the server-side code, for marshaling out the server object, yes?
前两行在服务器端代码中,用于编组服务器对象,是吗?
In that case, yes, the third line is the simplest you can get at client-side.
在这种情况下,是的,第三行是您在客户端可以获得的最简单的行。
In addition, you can serve out additional server-side objects from the MyServerObjectinstance, if you include public accessors for them in IRemoteServerinterface, so, accessing those objects become the simple matter of method calls or property accesses on your main server object, so you don't have to use activator for every single thing:
此外,您可以从MyServerObject实例提供额外的服务器端对象,如果您在IRemoteServer接口中为它们包含公共访问器,那么访问这些对象就变成了主服务器对象上的方法调用或属性访问的简单问题,所以您不必对每一件事都使用激活器:
//obtain another marshalbyref object of the type ISessionManager:
ISessionManager = MyServerObject.GetSessionManager();
回答by nickd
WCF.
周转基金。
I have used IPC before there was a WCF, and believe me, IPC is a bear. And it isn't documented fully/correctly.
在有 WCF 之前我就使用过 IPC,相信我,IPC 是个熊。并且它没有完全/正确地记录。
What's the simplest way to connect to a .NET remote server object? WCF.
连接到 .NET 远程服务器对象的最简单方法是什么?周转基金。