进程外COM服务器-每个调用进程一个服务器进程? [英] Out of Process COM Server - One server process per calling process?

查看:168
本文介绍了进程外COM服务器-每个调用进程一个服务器进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进程外的com服务器,指定CLSCTX_LOCAL_SERVER作为上下文,并指定REGCLS_MULTIPLEUSE作为连接类型。这导致单个服务器进程被来自多个客户端的多个调用重用。

I have an out of process com server, specifying CLSCTX_LOCAL_SERVER as the context, and REGCLS_MULTIPLEUSE for the connection type. This results in a single server process being reused by multiple calls from multiple clients.

我现在想对服务器进行一些更改,不幸的是,该更改无法使用客户之间共享一个流程(这是有原因的,但长期存在)。我知道您可以将服务器设置为使用REGCLS_SINGLEUSE作为连接类型,这将为OOP服务器的每个调用创建一个新进程。这解决了我的问题,但是对于流程使用而言却是一个入门者。短期内多次调用会导致许多过程,并且可能经常难以置信地击中该特定服务器。

I’m now wanting to make some changes to the server, which unfortunately can not work with a single process shared amongst clients (there are reasons for this, but they're long winded). I know you can set the server to use REGCLS_SINGLEUSE as the connection type, and this will create a new process for the OOP server each call. This solves my issue, but is a non-starter in terms of process usage; multiple calls over short periods result in many processes and this particular server might be hit incredibly often.

有人碰巧知道混合这两种连接类型的机制吗?本质上,我想要的是每个调用进程一个服务器进程。 (即,客户端一个创建了一个进程,该进程被重用于该客户端的后续调用。客户端两个尝试调用服务器,并创建了一个新进程)。我怀疑可以通过强制REGCLS_SINGLEUSE服务器在客户端中永久保持打开状态来实现此目的,但这既不优雅,也不可能(因为我无法更改其中一个客户端)。

Does anyone happen to know of a mechanism to mix those two connection types? Essentially what I want is a single server process per calling process. (ie, client one creates a process, and that process is reused for subsequent calls from that client. Client two tries to call the server, and a new process is created). I suspect I could achieve it by forcing a REGCLS_SINGLEUSE server to stay open permanently in the client, but this is neither elegant nor possible (since I can’t change one of the clients).

有什么想法?

更新
就像预期的那样是没有办法做到这一点。如果时间和资源允许,我极有可能将其转换为In-Proc解决方案。但就目前而言,我必须继续将新的行为用于所有调用客户端。幸运的是,此更改的影响非常小,并为客户所接受。

UPDATE As expected, it seems there is no way to do this. If time and resource permitted I would most likely convert this to an In-Proc solution. For now though, I'm having to go with the new behaviour being used for any calling client. Fortunately, the impact of this change is incredibly small, and acceptable by the clients. I'll look into more drastic and appropriate changes later.

注意
我已将汉斯的回答标记为答案,实际上,它确实为维护OOP解决方案的问题提供了解决方案。我只是没有能力实现它。

NOTE I've marked Hans' reply as the answer, as it does in fact give a solution to the problem which maintains the OOP solution. I merely don't have capacity to implement it.

cal

推荐答案

COM不支持此激活方案。它应该由进程内服务器覆盖,鉴于其相当大的优势,请确保这不是您想要的方式。

COM does not support this activation scenario. It is supposed to be covered by an in-process server, do make sure that isn't the way you want to do it given its rather major advantages.

使用REGCLS_SINGLEUSE是替代方法,但这需要您扩展对象模型,以避免当前创建的服务器实例大量涌入。 Application 协同类是样板方法。为它提供工厂方法,为您提供现有接口的实例。

Using REGCLS_SINGLEUSE is the alternative, but this requires you extending your object model to avoid the storm of server instances you now create. The Application coclass is the boilerplate approach. Provide it with factory methods that gives you instances to your existing interfaces.

我将提到一种截然不同的方法,当我想解决与很好,但是需要一个进程外服务器,以弥合位数差距。您不必担心COM为您启动服务器进程,客户端也可以启动它。当然,前提是它足够了解服务器的安装位置。现在,客户端当然可以完全控制服务器实例了。带有更改的CLSID的名为CoRegisterClassObject()的服务器,将GUID的一部分与进程ID进行了异或。客户端执行了相同的操作,因此它始终与正确的服务器连接。客户端需要额外的代码以确保其等待足够长的时间,以使服务器有机会注册其对象工厂。工作得很好。

I'll mention a drastically different approach, one I used when I wanted to solve the same problem as well but required an out-of-process server to take advantage of bridging a bitness gap. You are not stuck with COM launching the server process for you, a client can start it as well. Provided of course that it knows enough about the server's installation location. Now a client of course has complete control over the server instance. The server called CoRegisterClassObject() with an altered CLSID, I xored part of the guid with the process ID. The client did the same so it always connected with the correct server. Extra code was required in the client to ensure it waits long enough to give the server a chance to register its object factories. Worked well.

这篇关于进程外COM服务器-每个调用进程一个服务器进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆