COM+ 使用 C# 和 .NET 的事件
我试图通过 COM 访问应用程序的某些部分,主要是因为我需要 Delphi 应用程序能够调用 .NET 应用程序上的某些服务。
我已经设法通过继承自 ServicedComponent 类的 COM 公开一些方法,并且它工作正常。
现在我需要能够向客户提出事件,以便在发生某些事情时我可以提醒他。 我目前有这样的东西:
public interface IEvents
{
void OnMessage();
}
[EventClass]
[ComVisible(true)]
public class MyEventsClass : ServicedComponent, IEvents
{
public void OnMessage()
{
}
}
但是当我从 Delphi 导入 TypeLibrary 时,我得到这个:
IEvents = interface(IDispatch)
['{E7605303-F968-3509-829B-BF70084053C4}']
procedure OnMessage; safecall;
end;
IEventsDisp = dispinterface
['{E7605303-F968-3509-829B-BF70084053C4}']
procedure OnMessage; dispid 1610743808;
end;
我真的不知道如何使用。 我期待一个 IUnknown 接口,我可以通过 MyService.Register(IEvents events) 实现并提供给服务...
我想我完全迷失在这里...有关如何正确实现 COM+ 事件的任何建议或参考。网?
I'm trying to get access to certain parts of my application through COM, mainly because I need a Delphi application to be able to invoke certain services on the .NET application.
I've managed to expose some methods via COM inheriting from ServicedComponent class and its working fine.
Now I need to be able to raise events to the client so I can alert him when certain things occur. I currently have something like this:
public interface IEvents
{
void OnMessage();
}
[EventClass]
[ComVisible(true)]
public class MyEventsClass : ServicedComponent, IEvents
{
public void OnMessage()
{
}
}
but when I import the TypeLibrary from Delphi I get this:
IEvents = interface(IDispatch)
['{E7605303-F968-3509-829B-BF70084053C4}']
procedure OnMessage; safecall;
end;
IEventsDisp = dispinterface
['{E7605303-F968-3509-829B-BF70084053C4}']
procedure OnMessage; dispid 1610743808;
end;
which I don't really know how to use. I was expecting an IUnknown interface that I can implement and provide to the service through a MyService.Register(IEvents events)...
I think I'm completely lost here... Any advice or reference about how to properly implement COM+ events with .NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我仍然不确定 EventClass 到底有什么用途,因为我发现您不需要使用它。 我只是简单地声明了这一点:
并且该接口将作为 IUnknown 接口导出到 Delphi。
然后,您在 ServicedComponent 类上定义一个方法,该方法的连接签名如下:
这使您可以手动处理每个客户端事件处理程序的调用,但这是我找到的唯一方法。
I'm still unsure of what exactly is the use for EventClass by I've discovered you don't need to use it. I simply have declared this:
And with that the interface is exported as an IUnknown interface to Delphi.
Then you define a method on your ServicedComponent class which a connect signature like this:
which left you to manually handle the invoke of each client event handler but is the only way I've found.