Need help implementing Observer pattern between separate applications

Oct 28 2008 8:48 AM
First, let me preface my post by saying that I am a java developer and completely new to .NET and C#, so please forgive my ignorance.  I am working on integrating two windows applications; one is written in C# and the other in VB.  My job is to create a dll that will expose a method to be called by the C# application and then raise an event to notify the VB application that something has occurred (i.e., Observer pattern).

Existing C# app (call dll ScreenPop.OnCallEstablished method) --> ScreenPop dll (raise CallEstablished event) --> Existing VB app (listens for ScreenPop.CallEstablished event)


I've created a new class library project in C# that contains two classes - shown below.  One class contains the method to be called by the existing C# app and the event to be raised to the VB app.  The second class is for the event arguments.

I now need to modify the existing C# application to invoke the method on my dll.  And, I need to create a test stub VB program as a separate solution that will implement the event handler and just print the fields in the event arguments.

The problem I'm having is how to get these applications to talk to each other.  I've tried registering my new project as COM visible, creating a strong name key, registering with regasm, and adding to the global assembly cache.  However, even after I do all of this, I can not add a reference to the COM object in the other solutions.
 
If anyone can please list the steps I need to follow to integrate these applications, it would be most appreciated.

Thanks,
Mark

=========================================================================================================

// Class #1 - ScreenPop
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MyScreenPop
{
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface _ScreenPop
    {
        [DispId(1)]
        void OnCallEstablished(string interactionId, string accountNumber, string ani, string dnis);
    }

    public delegate void CallEstablishedEventHandler(Object sender, CallEstablishedEventArgs e);
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
    public interface UserEvents
    {
        [DispId(2)]
        void CallEstablished(CallEstablishedEventArgs e);
    }

    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("MyScreenPop.ScreenPop")]
    [ComSourceInterfaces(typeof(UserEvents))]
    public class ScreenPop : _ScreenPop
    {
        public event CallEstablishedEventHandler CallEstablished;

        // constructor
        public ScreenPop()
        {
        }

        public void OnCallEstablished(string interactionId, string accountNumber, string ani, string dnis)
        {
            CallEstablished(this, new CallEstablishedEventArgs(interactionId, accountNumber, ani, dnis));

        }
    }
}

=========================================================================================================
// Class #2 - CallEstablishedEventArgs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MyScreenPop
{
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface _CallEstablishedEventArgs
    {
        [DispId(1)]
        string InteractionId {get; set;}
        [DispId(2)]
        string AccountNumber { get; set; }
        [DispId(3)]
        string ANI { get; set; }
        [DispId(4)]
        string DNIS { get; set; }

    }

    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("MyScreenPop.CallEstablishedEventArgs")]
    public class CallEstablishedEventArgs : EventArgs, _CallEstablishedEventArgs
    {
        // private fields
        private string interactionId;
        private string accountNumber;
        private string ani;
        private string dnis;

        // constructor
        public CallEstablishedEventArgs(string interactionId, string accountNumber, string ani, string dnis)
        {
            this.interactionId = interactionId;
            this.accountNumber = accountNumber;
            this.ani = ani;
            this.dnis = dnis;
        }

        // properties
        public string InteractionId
        {
            get { return interactionId; }
            set
            {
                interactionId = value;
            }
        }

        public string AccountNumber
        {
            get { return accountNumber; }
            set
            {
                accountNumber = value;
            }
        }

        public string ANI
        {
            get { return ani; }
            set
            {
                ani = value;
            }
        }

        public string DNIS
        {
            get { return dnis; }
            set
            {
                dnis = value;
            }
        }

    }
}