I'm trying to hook the event (Action in that case) but cant return from proxy without exception. Here's the idea: I have the interface of events, they not subscribed on client side. So when I try raise event on client side, I catch this event in proxy and send to my remote server the name of this event and his parameters and i wanna just return from proxy. Here my sample
public interface IMyEvents
{
Action OnPing { get; set; }
}
public class Proxy : RealProxy
{
Type type;
public Proxy(Type type)
: base(type)
{
this.type = type;
}
public override IMessage Invoke(IMessage msg)
{
var call = (IMethodCallMessage)msg;
string MethodName = (string)msg.Properties["__MethodName"];
object[] parameters = (object[])msg.Properties["__Args"];
// Send Command to server
// SendData(MethodName, parameters);
// tell the invoker that everything's fine
return new ReturnMessage(null, null, 0, call.LogicalCallContext, call);
}
}
public class Test
{
public Test()
{
Proxy proxy = new Proxy(typeof(IMyEvents));
Events = (IMyEvents)proxy.GetTransparentProxy();
}
public readonly IMyEvents Events;
}
class Program
{
public static void Main(string[] args)
{
Test t = new Test();
t.Events.OnPing(); // NullReferenceException
}
}