公共类成员在 VB6 IDE 中似乎不可用
我创建了一个 .net 程序集,其中包含 WCF (win32) 服务的数据协定。然后,我通过 COM Interop 公开这些对象,以便可以在客户端重复使用相同的程序集来调用 WCF 服务。我的项目包含以下部分:
[wcf 服务] <====> { [通过 COM 互操作公开的 wcf 客户端程序集] + [也通过 com 互操作公开的数据契约程序集] } <==> [vb 6 应用]
数据契约中的类的一个示例如下:
[Guid("00000000-0000-0000-0000-000000000000")]
[ComVisible(true)]
[DataContract]
public sealed class Monkey {
public string name;
};
而且,大多数情况下,它工作得很好。我能够编译包含此类的 .net 程序集,将其注册为 COM 互操作,在 VB6 项目中引用它,并从客户端应用程序调用 WCF 服务。
这里有一个奇怪的行为:它在 VB6 IDE 对象浏览器中显示类 Monkey,但不显示 Monkey.name 等成员。
我相信这是由导致 .net 程序集项目中出现以下编译时警告的同一原因引起的:
类型库导出器警告处理“MyCompany.Product.Contracts、MyCompany.Product.API”。警告:类型库导出程序遇到从泛型类派生且未标记为 [ClassInterface(ClassInterfaceType.None)] 的类型。不能为此类类型公开类接口。考虑使用 [ClassInterface(ClassInterfaceType.None)] 标记类型,并使用 ComDefaultInterface 属性将显式接口公开为 COM 的默认接口。
最后,我认为开发客户端应用程序时出现警告和奇怪行为的原因是我使用自动生成的服务引用和继承自 System.ServiceModel 的客户端对象.ClientBase
我走在正确的道路上吗?
如何解决此问题/警告?
I've created a .net assembly that includes the data contract for a WCF (win32) service. I then exposed these objects via COM Interop so that the same assembly can be re-used on the client side for calling the WCF service. I've got the following pieces to my project:
[wcf service] <====> { [wcf client assembly exposed through COM interop] + [data contracts assembly also exposed through com interop] } <==> [vb 6 application]
One example of a class in the data contract is like this:
[Guid("00000000-0000-0000-0000-000000000000")]
[ComVisible(true)]
[DataContract]
public sealed class Monkey {
public string name;
};
And, mostly, it works just fine. I'm able to compile the .net assembly that includes this class, register it for COM interop, refer to it in the VB6 project, and call through to the WCF service from the client application.
Here's the strange behavior: It displays the class Monkey in the VB6 IDE object browser, but does not display the members like Monkey.name.
I believe that this is being caused by the same thing that causes the following compile-time warning in the .net assembly project:
Type library exporter warning processing 'MyCompany.Product.Contracts, MyCompany.Product.API'. Warning: Type library exporter encountered a type that derives from a generic class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot be exposed for such types. Consider marking the type with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as the default interface to COM using the ComDefaultInterface attribute.
And, finally, I think that the cause of both the warning and the strange behavior while developing the client application is being caused by the fact that I'm using the automatically generated service reference and client object that inherits from System.ServiceModel.ClientBase<T>
.
Am I on the right track?
How can I resolve this issue/warning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决此问题的常用方法是创建一个由您的类实现的 ComVisible 接口 IMonkey。
结果类似于 这个类似的问题。
The usual way to resolve this would be to create a ComVisible interface IMonkey that is implemented by your class.
The result would be something like the example in this similar question.