如何在 C# 服务和单独的 VB 6 应用程序之间来回传递结构(或类)消息?
我需要在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
您可以使用任何 .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.
我同意 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.