【问题标题】:connect to a service with .NET remoting in a service在服务中使用 .NET 远程处理连接到服务
【发布时间】:2014-01-21 18:38:18
【问题描述】:

由于不明原因,我需要使用 .NET 从服务本身远程连接到服务。

澄清: 有一个客户端应用程序连接到该服务:

IEngine engine = (IEngine)Activator.GetObject(typeof(IEngine), "tcp://169.18.1.100:1966/Engine");

当对服务进行特定调用时,它会加载一个带有插件 dll 的 AppDomain,该插件 dll 会计算一些东西。但是现在这个 dll 需要从它嵌入的服务中调用函数并且它不能直接调用它们,因为它存在于它自己的 AppDomain 中。

那么我可以从 AppDomain 中调用它吗?

IEngine engine = (IEngine)Activator.GetObject(typeof(IEngine), "tcp://localhost:1966/Engine");

对象的发布方式:

RemotingServices.Marshal(this, engineUri);

它至少对单次调用有效,但可能需要考虑 IEngine 的线程和释放或其他问题?

我希望它清楚。

【问题讨论】:

  • 您的对象是配置为单调用还是单例?
  • 该对象是使用 RemotingServices.Marshal(this, engineUri) 发布的,所以我猜它就像一个单身人士

标签: c# .net remoting


【解决方案1】:

如果您存储传递给RemotingServices.MarshalIEngine 的实例,那么您不需要从服务本身调用Activator.GetObject,因为它将与客户端应用程序使用的实例相同。它可能需要一些重组,但它会保存从您的服务中通过网络堆栈对IEngine 的任何调用:

IEngine this.engine = new Engine();
RemotingServices.Marshal(this.engine, engineUri);

// this.engine will be the same instance used by client applications and can also be passed around within your service.

【讨论】:

  • 听起来不错,但是在将其放入程序集类的构造函数后,每个调用都返回 null,因为在方法中使用了 ConfigurationManager 设置。如果出现性能问题,我会坚持使用 Activator.GetObject 并修复它们
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多