使用 .NET 远程处理注册对象 _instances_ 而不是 _types_?
关于 .NET 远程处理,我有些不明白。 好吧,实际上有两件事:
为什么重点回到从 MarshalByRef 继承的类而不是原始 COM 风格(我喜欢的)的接口?
为什么 .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:
Why is the emphasis back on classes that inherit from MarshalByRef instead of interfaces ala the original COM style (which I liked)?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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
我无法真正解决第 1 点和第 2 点,因为我没有 COM 经验,而且我不理解第 2 点,但是要回答您具体的最终问题,如果您使用 system.Activator 类,您可以这样做:
这意味着您必须在构建时绑定它,但这都是客户端的。
请参阅我的类似问题 。
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:
It means you have to bind it at construction time, but it's all client side.
See my similar question.