如何优雅地防止 Web 服务代理暴露给 COM?
我有一个 C# 程序集,用作非托管 C++ 应用程序使用的进程内 COM 服务器。该程序集使用永远不会更改的 Web 服务,因此无需更新 Web 服务代理类。这就是为什么代理类创建一次,并且将 Reference.cs
文件简单地放入存储库中并仅从那里进行编译。
问题是默认情况下 Web 服务代理类是公共的,因此暴露给 COM。这会导致类型库膨胀并污染注册表。将可见性更改为内部会破坏程序集,因此这些实体需要保持公共状态,但不需要暴露给 COM。
愚蠢的方法是处理 Reference.cs
文件中的每个公共接口/类,并用
[System.Runtime.InteropServices.ComVisible(false)]
After 标记它,这样它就不再暴露给 COM。
有更好的办法吗?
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 created once and Reference.cs
files are simply put into the repository and only compiled from there.
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.
The dumb way is to approach every public interface/class in the Reference.cs
files and mark it with
[System.Runtime.InteropServices.ComVisible(false)]
After that it is no longer exposed to COM.
Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以
ComVisible
,然后将要公开给COM
的所有接口/类/枚举显式标记为ComVisible
。使用第二个文件和分部类将您的代理类型标记为
ComVisible(false)
You could
ComVisible
and then explicitly mark all interfaces/classes/enums you want to expose toCOM
asComVisible
.use a 2nd file and partial class to mark your proxy types to be
ComVisible(false)