What's the simplest way to connect to a .NET remote server object

▼魔方 西西 提交于 2019-12-11 05:56:43

问题


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));

回答1:


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 MyServerObject instance, if you include public accessors for them in IRemoteServer interface, 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:

//obtain another marshalbyref object of the type ISessionManager:
ISessionManager = MyServerObject.GetSessionManager();



回答2:


WCF.

I have used IPC before there was a WCF, and believe me, IPC is a bear. And it isn't documented fully/correctly.

What’s the simplest way to connect to a .NET remote server object? WCF.



来源:https://stackoverflow.com/questions/25982/whats-the-simplest-way-to-connect-to-a-net-remote-server-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!