如何在 C# 服务和单独的 VB 6 应用程序之间来回传递结构(或类)消息?

发布于 2024-08-28 13:50:16 字数 868 浏览 8 评论 0原文

我需要在 ac# 服务和正在运行的 vb 6 应用程序之间传递数据,考虑使用 Windows Messaging。如何在 C# 服务和正在运行的 VB 6 应用程序之间来回传递数据?我来回传递的数据的简短示例如下:

namespace MainSection
{
    public struct Info
    {

    private int _Id;
    private string _TypeCode;
    private float _Calc;
    private DateTime _ProcessDate;
    private bool _ProcessFlag;

    public int Id
    {
        get { return _Id; }
        set { _Id = value; }
    }

    public string TypeCode
    {
        get { return _TypeCode; }
        set { _TypeCode = value; }
    }

    public float Calc
    {
        get { return _Calc; }
        set { _Calc = value; }
    }

    public DateTime ProcessDate
    {
        get { return _ProcessDate}
        set { _ProcessDate = value; }
    }

    public bool ProcessFlag
    {
        get { return _ProcessFlag}
        set { _ProcessFlag = value; }
    }
   }
}

I need to pass data between a c# service and a running vb 6 application, considering using Windows Messaging. How do I pass the data back and forth between a C# service and a running vb 6 application? Shortened sample of the data I am passing back and forth is below:

namespace MainSection
{
    public struct Info
    {

    private int _Id;
    private string _TypeCode;
    private float _Calc;
    private DateTime _ProcessDate;
    private bool _ProcessFlag;

    public int Id
    {
        get { return _Id; }
        set { _Id = value; }
    }

    public string TypeCode
    {
        get { return _TypeCode; }
        set { _TypeCode = value; }
    }

    public float Calc
    {
        get { return _Calc; }
        set { _Calc = value; }
    }

    public DateTime ProcessDate
    {
        get { return _ProcessDate}
        set { _ProcessDate = value; }
    }

    public bool ProcessFlag
    {
        get { return _ProcessFlag}
        set { _ProcessFlag = value; }
    }
   }
}

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

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

发布评论

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

评论(3

剧终人散尽 2024-09-04 13:50:16

WCF 是 Microsoft 目前推荐的用于构建需要跨平台互操作的应用程序的技术。有一个 MSMQ 绑定(我想这就是您所说的“Windows 消息传递”),它允许您在一对 MSMQ 队列上发送和接收消息。 MSMQ 类也作为 COM 对象公开,因此 VB6 应用程序也能够从队列中读取和写入。您需要在 .NET 中使用正确的 DataContract 属性来标记数据传输对象,您甚至可以不必将 .NET 对象公开为 COM 对象,从而避免重复。

WCF is Microsoft's currently recommended technology for building applications that require cross-platform interop. There is an MSMQ binding (I presume this is what you refer to by "Windows Messaging",) which will allow you to send and receive messages on a pair of MSMQ queues. The MSMQ classes are also exposed as COM objects, so the VB6 application would be able to read and write from the queues too. You would need to mark up your data transfer objects with the correct DataContract attributes in .NET, and you might even be able to get away with exposing your .NET objects as COM objects and avoid having to repeat yourself.

来世叙缘 2024-09-04 13:50:16

您可以使用任何 .NET 语言围绕 C# 服务编写包装器,然后将包装器公开为 COM 对象。然后可以在 VB6 应用程序中使用它。让 C# 服务托管 WCF 服务,然后让包装器使用“添加服务引用”作为客户端访问它。

You could write a wrapper around the C# service in any .NET language, then expose the wrapper as a COM object. It could then be used from the VB6 application. Have the C# service host a WCF service, then have the wrapper use "Add Service Reference" to access it as a client.

零度℉ 2024-09-04 13:50:16

我同意 John Saunders 通过 COM 公开 C# 代码的方法。我还应该补充一点,相反的方法也可以,如果您习惯了 VB6,可能会更自然。 VB6 COM 组件很容易被 C# 代码使用。

I agree with John Saunders' approach of exposing the c# code via COM. I should also add that the opposite also works, and might be more natural if you're used to VB6. A VB6 COM component is easily consumed by c# code.

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