公共类成员在 VB6 IDE 中似乎不可用

发布于 2024-09-19 04:38:08 字数 1084 浏览 4 评论 0原文

我创建了一个 .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

  1. 我走在正确的道路上吗?

  2. 如何解决此问题/警告?

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>.

  1. Am I on the right track?

  2. How can I resolve this issue/warning?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落画卷 2024-09-26 04:38:09

解决此问题的常用方法是创建一个由您的类实现的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文