问题描述
我有一个,我作为非托管C ++应用程序消耗的进程内COM服务器使用C#程序集。该组件消耗的永远不会改变,因此没有必要不断更新Web服务代理类web服务。这就是为什么代理类创建donce和 Reference.cs
文件简单地把到库中,并从那里只有编译。
I have a C# assembly that I use as an in-proc COM server consumed by an unmanaged C++ application. The assembly consumes a webservice that will not ever change so there's no need to ever update the webservice proxy classes. That's why the proxy classes are create donce and Reference.cs
files are simply put into the repository and only compiled from there.
问题是,默认情况下,Web服务代理类是公共的,因此暴露在COM。这种膨胀的类型库,污染注册表。更改可视性内部破组装,因此这些实体需要保持公开,但不必暴露在COM。
The problem is that by default the webservice proxy classes are public and are therefore exposed to COM. This inflates the typelib and pollutes registry. Changing visibility to internal break the assembly, so those entities need to remain public, but need not be exposed to COM.
装聋作哑的方法是接近每一个公共接口/类中的 Reference.cs
文件并将其标记与
The dumb way is to approach every public interface/class in the Reference.cs
files and mark it with
[System.Runtime.InteropServices.ComVisible(false)]
之后,它不再暴露在COM。
After that it is no longer exposed to COM.
有没有更好的办法?
推荐答案
您可以
- 在纪念集会本身不被标记有ComVisible特性,然后明确标记要暴露给COM作为标记有ComVisible特性的所有接口/类/枚举。
-
使用第二个文件,部分类,以纪念你的代理类型是标记有ComVisible特性(假)
- mark the assembly itself to not to be ComVisible and then explicitly mark all interfaces/classes/enums you want to expose to COM as ComVisible.
use a 2nd file and partial class to mark your proxy types to be ComVisible(false)
[System.Runtime.InteropServices.ComVisible(假)]部分类YourProxyType {}
[System.Runtime.InteropServices.ComVisible(false)]partial class YourProxyType {}
[System.Runtime.InteropServices.ComVisible(假)]部分类AnotherProxyType {}
[System.Runtime.InteropServices.ComVisible(false)]partial class AnotherProxyType {}
这篇关于如何优雅地prevent暴露给COM一个web服务代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!