.Net Remoting:序列化对象和实现

发布于 2024-08-26 13:21:43 字数 462 浏览 1 评论 0原文

在我的场景中,有一个包含类(任务)的客户端程序集。 此类实现服务器上已知的接口(ITask)。 我试图将任务对象从客户端发送到服务器,而不将客户端的程序集手动复制到服务器。

如果我只是序列化任务对象,服务器显然会抱怨缺少程序集。 然后我尝试序列化 typeof(Task).Assembly 但无法在服务器上反序列化它。 接下来,我尝试 File.ReadAllBytes(typeof(Task).Assembly.Location) 并将其保存到服务器上的临时文件中,这在 Assembly.LoadFrom(@".\temporary.dll"); 上引发了异常

我为什么要这样做? Java RMI 有一个巧妙的功能,可以请求实现通过远程接收但仍然“未知”的对象(该 JVM 没有 *.class 文件)。这可用于只知道包含 run() 方法的“任务”接口并按需下载该方法的实现的计​​算服务器。 这样就不必为新任务更改服务器。 我正在尝试在.Net 中实现类似的目标。

In my scenario there is a client-side assembly that contains a class (Task).
This class implements an interface (ITask) that is known on the server.
I'm trying to send a Task object from client to server without copying the assembly of the client manually to the server.

If I just serialize the task object, the server obviously complains about the missing assembly.
I then tried to serialze typeof(Task).Assembly but could not derserialize it on the server.
Next I tried to File.ReadAllBytes(typeof(Task).Assembly.Location) and saved it to a temporary file on the server, which threw an exception on Assembly.LoadFrom(@".\temporary.dll");

Why am I doing this? Java RMI has a neat feature to request the implementation of an object that is received through remoting but is stil "unkown" (this JVM doesn't have the *.class file). This can be used for a compute server that just knows the interface of a "task" containing a run() method and downloads the implementation of this method on demand.
This way the server doesn't have to be changed for new tasks.
I'm trying to achieve something like this in .Net.

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

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

发布评论

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

评论(1

辞取 2024-09-02 13:21:43

没关系,我找到了一种适合我的方法,使用 AssemblyResolve 事件并直接从字节数组加载程序集,以防

AppDomain.CurrentDomain.Load(assemblyData);

万一有人遇到同样的问题。

Never mind, I found a way that works for me using the AssemblyResolve event and loading the assembly directly from the byte array with

AppDomain.CurrentDomain.Load(assemblyData);

Just in case someone has the same problem.

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