简体   繁体   English

使用.net远程处理来调用本地“远程”?

[英]Use .net remoting to call a local “remote”?

I have a large app which uses COM via .net remoting to call from the web tier to the middle tier. 我有一个大型应用程序,该应用程序通过.net远程处理使用COM从Web层调用到中间层。 It's quite slow to startup and to run when in this mode. 在这种模式下,启动和运行相当慢。 Both sides of the COM boundary are our code. COM边界的两侧都是我们的代码。

I'd like to be able to (optionally) run it in a single process. 我希望能够(可选)在一个过程中运行它。 Quite a bit of the behaviour relies on calls to ServicedComponents having all their arguments serialized, and that changes made to the objects inside the components don't leak out unless the argument is a 'ref' argument. 相当一部分行为依赖于对所有参数都序列化的ServicedComponents的调用,并且除非参数为“ ref”参数,否则不会泄漏对组件内部对象的更改。

My current plan to force this two-process app into a single process without needing to change too much code is by using a fake middle tier boundary with custom .net remoting. 我当前的计划是将这个两个进程的应用程序强制为一个进程,而无需更改太多代码,这是使用带有自定义.net远程处理的伪中间层边界。

If I change all the: 如果我全部更改:

class BigComponent : ServicedComponent {
   ...
}

into 进入

[FakeComponent]
class BigComponent : ContextBoundObject {
   ...
}

Then I can write a custom ContextAttribute to fake the process boundary and make the arguments serialize themselves: 然后,我可以编写一个自定义ContextAttribute来伪造进程边界并使参数序列化自己:

ie

[AttributeUsage(AttributeTargets.Class)]
public class FakeComponentAttribute :
  ContextAttribute,
  IContributeServerContextSink
{
   ... lots of stuff here
}

As per http://msdn.microsoft.com/en-us/magazine/cc164165.aspx 按照http://msdn.microsoft.com/en-us/magazine/cc164165.aspx

Now this works fine, so far, and I can intercept all calls to methods on these classes. 到目前为止,现在一切正常,我可以拦截这些类上对方法的所有调用。 However, I can only view the IMethodCallMessage.Args in the IMessageSink.ProcessMessage call -- I don't seem to be able to replace them with objects of my choice. 但是,我只能在IMessageSink.ProcessMessage调用中查看IMethodCallMessage.Args -我似乎无法用我选择的对象替换它们。

Any time I change entries in the IMethodCallMessage.Args array, my changes are ignored. 每当我更改IMethodCallMessage.Args数组中的条目时,我的更改都会被忽略。 From what I can tell in Reflector, this interface is a wrapper around a native object in the runtime itself, and I can't write to this object, just read it. 根据我在Reflector中的了解,该接口是运行时本身中本机对象的包装,并且我无法写入该对象,而只能读取它。

How can I modify the arguments to method calls in .net remoting? 如何修改.net远程处理中方法调用的参数?

Do I need to implement my own Channel? 我需要实现自己的频道吗? Is there a "local" channel tutorial out there I can crib from? 我可以从那里找到“本地”频道教程了吗?

My aim is to have these Components act like remote objects (in that all their args get serialized on the way in to the method, and that their return value is serialized on the way out), but have the remote endpoint be inside the same process. 我的目标是使这些组件像远程对象一样起作用(因为它们的所有arg都在进入方法的过程中被序列化,并且它们的返回值在退出的过程中被序列化),但使远程端点位于同一进程内。

I have not found a way to edit the argument array as it passes through the IMessageSink . 我没有找到一种方法来编辑通过IMessageSink传递的参数数组。

In the end, I had to make the argument object classes aware of this issue, and implement a new interface IFakeRemotingAware . 最后,我必须使参数对象类意识到此问题,并实现一个新接口IFakeRemotingAware This allowed the complex object arguments which exhibit the pass-by-val behaviour due to serialization/deserialization when using remoting to simulate that behaviour when using fake remoting. 这允许使用远程处理时由于序列化/反序列化而表现出传递值行为的复杂对象参数,而在使用伪远程处理时模拟该行为。

The interface has two methods: EnteringFakeRemote which causes the object to cache a local copy of its state, and LeavingFakeRemote which causes the object to restore its state from the cache. 该接口有两种方法: EnteringFakeRemote (使对象缓存其状态的本地副本)和LeavingFakeRemote (使对象从缓存中恢复其状态)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM