应用程序域之间的通信应用程序、通信

2023-09-04 00:34:08 作者:倾尽余生来爱你

我们正在建立一个应用程序(的WinForms,.NET 3.5)加载插件的DLL到一个次要的AppDomain。次级的AppDomain需要与第一1偶尔通信(更具体地,呼叫或来自为主的AppDomain创建的对象获得的数据)。

我看了大部分材料有关他们之间的AppDomain和沟通。

到目前为止,只有简单的解决方案我已经看到了继承的的 MarshalByRefObject的的并传递一个的的 TransparentProxy 的到第二AppDomain中,呼吁代理的方法。

该方法也有缺点(并不总是能够从MBRO的情况下,例如框架类型,或类型已经从另一个类,静态字段/班等继承继承)。

由于当前通信点pretty的常数(需要通信只有2-3个场景),我已经考虑用下面创建一个简单的的中保的类属性:

将在第1(主)的AppDomain中创建。 仅会作为一个消息过路人,以被主AppDomain中创建的真实的对象。 将继承MBRO,以及代理引用都将被发送到第二应用程序域 TCP IP 应用程序的通信连接模式

此代理对象的方法将被调用,这反过来会呼吁真正的对象的方法在第一AppDomain中。

我的提问 -

这看起来像一个逻辑设计? 更重要的是,它的中介/消息路人类已经在WCF或任何其他各项通讯框架存在吗?这似乎是一个通用的概念,我想知道是否有类似的东西。 解决方案

除非你特别想避免WCF出于某种原因,我建议考虑看看吧。具体而言,可以使用NetNamedPipeBinding,它提供了使用命名管道在同一台机器上的沟通。你可以在这里找到一些详细信息: 的http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx

同时,这里是一个相当简洁的博客中展示了它的使用的(从一个WMP插件以第三方应用程序)。

根据您的应用程序的描述,你可以在第一个AppDomain中建立一个WCF服务,然后调用到从第二AppDomain中的服务。

We are building an app (WinForms, .NET 3.5) that loads "Plugin" DLLs into a secondary AppDomain. The secondary AppDomain needs to communicate occasionally with the 1st one (more specifically, call or get data from objects that are created in the main AppDomain).

I have read most of the material about AppDomains and communication between them.

So far, the only easy solution i've seen was inheriting from MarshalByRefObject and passing a TransparentProxy into the 2nd AppDomain, calling methods on the Proxy.

This method has its drawbacks (not always possible to inherit from MBRO in case of framework types for example, or types that already inherit from another class, static fields/classes and so on).

Since the current communication points are pretty constant (only 2-3 scenarios that require communication), i have considered creating a simple Mediator class with the following properties:

Will be created in the 1st (Main) AppDomain. Would function only as a "message-passer" to the "Real" objects that are created in the main AppDomain. Will inherit from MBRO, and a proxy reference to it will be sent to the 2nd AppDomain.

Methods on this proxy object would be called, which in turn will call the methods on the "real" objects in the 1st AppDomain.

My questions --

Does this seem like a logical design? More importantly, does a mediator/message passer class already exist in WCF or any other communcation framework? it seems like a generic concept and i am wondering if there is something similar.

解决方案

Unless you specifically want to avoid WCF for some reason, I would suggest taking a look at it. Specifically, you can use the NetNamedPipeBinding, which provides for communication on the same machine using named pipes. You can find some more information here: http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx

As well, here is a reasonably concise blog entry demonstrating it's use (from a WMP plug-in to a third-party app).

Based on your description of the application, you could establish a WCF service in the first AppDomain then call into that service from the second AppDomain.