使用 .NET 远程处理注册对象 _instances_ 而不是 _types_?

发布于 2024-07-11 09:38:45 字数 702 浏览 6 评论 0原文

关于 .NET 远程处理,我有些不明白。 好吧,实际上有两件事:

  1. 为什么重点回到从 MarshalByRef 继承的类而不是原始 COM 风格(我喜欢的)的接口?

  2. 为什么 .NET 远程处理总是强制您有效地创建某种对象池,而不是允许您将特定实例与 URL 相关联?

服务器代码:

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingTypes.Server), "MyURL", WellKnownObjectMode.Singleton);

客户端代码:

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingTypes.Server), "MyURL", WellKnownObjectMode.Singleton);

但是假设我想自己创建“服务器”实例,然后将其绑定到端点?

RemotingTypes.Server myInstance = new RemotingTypes.Server();

现在怎么办? 如何将“myInstance”与 URL“MyURL”关联起来?

There's something I'm just not getting about .NET remoting. Well, two things actually:

  1. Why is the emphasis back on classes that inherit from MarshalByRef instead of interfaces ala the original COM style (which I liked)?

  2. Why is it that .NET remoting always forces you to effectively create some sort of object pool instead of allowing you to associate specific instances with a URL?

Server code:

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingTypes.Server), "MyURL", WellKnownObjectMode.Singleton);

Client code:

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingTypes.Server), "MyURL", WellKnownObjectMode.Singleton);

But suppose I want to create the "Server" instance myself and then just bind it to an endpoint?

RemotingTypes.Server myInstance = new RemotingTypes.Server();

What now? How can I associate "myInstance" with the URL "MyURL" ?

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

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

发布评论

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

评论(2

影子是时光的心 2024-07-18 09:38:45

Nickd 回答的问题是:我想知道如何将已创建的实例与 URL 关联,而不是如何让 .NET 远程处理为我执行此操作(我创建的某些实例没有默认构造函数,例如例子)。

我希望能有一些史诗般的回应来解释 .NET 远程处理背后的“哲学”,以及为什么它与类型系统密不可分……

我的结论很简单:
a) 这是因为 .NET 远程处理很糟糕。 不要使用它
b) 使用 WCF

The problem with Nickd's answer: I wanted to know how to associate an already created instance with a URL, rather than how to get .NET remoting to do this for me (some instance that I have created that does not have a default constructor, for example).

I was hoping there'd be some epic response explaining the "philosophy" behind .NET remoting, and why it's inextricably coupled to the type system...

What I've concluded instead is simply that:
a) It's because .NET remoting sucks. Don't use it
b) Use WCF instead

贵在坚持 2024-07-18 09:38:45

我无法真正解决第 1 点和第 2 点,因为我没有 COM 经验,而且我不理解第 2 点,但是要回答您具体的最终问题,如果您使用 system.Activator 类,您可以这样做:

RemotingTypes.Server  myInstance = (RemotingTypes.Server) Activator.GetObject(typeof(RemotingTypes.Server), MyUrl);

这意味着您必须在构建时绑定它,但这都是客户端的。

请参阅我的类似问题

I can't really address points 1 and 2 as I have no experience of COM and I don't understand 2, but to answer your specific final question, if you use the system.Activator class, you can do this:

RemotingTypes.Server  myInstance = (RemotingTypes.Server) Activator.GetObject(typeof(RemotingTypes.Server), MyUrl);

It means you have to bind it at construction time, but it's all client side.

See my similar question.

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