.net - 远程处理和缺少 channel 接收器

标签 .net remoting appdomain

我遇到了一个远程异常:

“这个远程代理没有 channel 接收器,这意味着服务器没有注册的服务器 channel 正在监听,或者这个应用程序没有合适的客户端 channel 来与服务器通信。”

this blog entry 可以很好地解释原因。我发现:

The second case is more obscure. This occurs where the client makes a call to the server, the server returns an object reference, and the client then makes a call on the referenced object on the server. If the referenced object is in a secondary AppDomain on the server the above exception may be thrown. If the the problem occurs it is because channel registration only applies to the AppDomain in which RegisterChannel is called and no channel has been registered in the secondary AppDomain. The object reference returned to the client points to the object in the secondary AppDomain, not to its proxy in the primary AppDomain, and so there is no channel between the client and the secondary AppDomain across which the call can pass. Solution: register a channel in the secondary AppDomain in which the referenced object exists.



这确实适合我的场景,因为我有一项服务可以将插件加载到单独的应用程序域中。对象实例(在所有程序集引用的程序集中定义的接口(interface)的实现)在辅助应用程序域中创建并由服务引用(跨应用程序域,因此服务具有代理引用)。然后服务将这些代理引用返回给应用程序。应用程序和服务之间有注册的 channel ,但插件和应用程序之间没有。

我认为代理足以跨越 appdomain 边界。我真的必须在插件和应用程序之间创建 channel 吗?这似乎根本不对,所以我一定是错过了什么。

最佳答案

扩展@RonCohen的答案-

在服务器上,通常会以有趣的方式创建一个完整的 channel (特别是如果您想修复 TypeLevelFilter 问题 ala https://stackoverflow.com/a/9268223/344638 ):

BinaryServerFormatterSinkProvider serverProvider;
BinaryClientFormatterSinkProvider clientProvider;
Hashtable properties = new Hashtable();

serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;

clientProvider = new BinaryClientFormatterSinkProvider();

properties.Add( "port", 8080 );

this.chan = new TcpChannel( properties, clientProvider, serverProvider );

ChannelServices.RegisterChannel( this.chan, true );

假设您在客户端使用赞助商。如果您不这样做,并且客户端暂时没有调用远程对象,则服务器将删除该对象:
Object '/70c96e17_02a8_4e1a_a040_7b671b4a66b4/3fssua+asfozgeqqkrjql+4k_1.rem' has been disconnected or does not exist at the server.

因此,您正在使用赞助商,然后服务器偶尔会调用赞助商来更新远程对象。但!现在服务器有一个远程对象 - 当赞助者调用 ILease.Register 时,赞助者被远程到服务器端。 .但是,如果服务器没有到客户端的远程 channel ,则会失败。

因此,与服务器必须向客户端公开远程 channel 以供客户端访问远程对象的方式相同,客户端必须向服务器公开远程 channel 以便服务器能够访问远程对象(如赞助商)。最后,我的客户端和服务器端最终都具有相同的 channel 构造代码(上图),除了我在每一端使用不同的端口号。

关于.net - 远程处理和缺少 channel 接收器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1657863/

相关文章:

c# - 静态变量在方法调用中为空,但在程序中已初始化

c# - 关闭 AppDomain 及其创建的所有 AppDomain

c# - 在应用程序域之间来回传递集合对象

java - 我可以从单个模型描述创建服务器端 Java 类、OR 映射和客户端 AS 类吗?

wcf - 企业服务总线和消息代理

file - 如何在另一个应用程序域中加载 dll 的配置文件

c# - 为什么我们在 Encoder.GetBytes 方法中使用刷新参数

.net - C++/命令行界面 : Add item to managed collection

.NET正则表达式允许3个重复字符

c# - AsQueryable() 在 ASP.NET 中是如何实现的