连接到 .NET 远程服务器对象的最简单方法是什么 [英] What's the simplest way to connect to a .NET remote server object

查看:46
本文介绍了连接到 .NET 远程服务器对象的最简单方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我的客户端代码知道它需要的关于远程对象的一切,连接到它的最简单方法是什么?

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

推荐答案

前两行是服务器端代码,用于编组出服务器对象,是吗?

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.

此外,您可以从 MyServerObject 实例提供额外的服务器端对象,如果您在 IRemoteServer 接口中包含它们的公共访问器,那么,访问这些对象成为主服务器对象上的方法调用或属性访问的简单问题,因此您不必对每件事都使用激活器:

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

这篇关于连接到 .NET 远程服务器对象的最简单方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆