views:

74

answers:

3

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; }
    }
   }
}
+2  A: 

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.

Jono
+1  A: 

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
A: 

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.

Jacob O'Reilly