static void Main(string[] args) { WorkOutMessage workOutMessage = new WorkOutMessage() { interfaceType = "HelloWorld.Service1", methodArgTypes = new string[] { "System.String" }, methodArgs = new object[] { "yeah it works!" }, methodName = "ServiceMethod" }; InvokeService(workOutMessage); Console.Read(); }
static void InvokeService(WorkOutMessage workOutMessage) { // Types var serviceT = Type.GetType(workOutMessage.interfaceType); // ServiceInvoker<T> Instantiation - Works var serviceInvokerT = typeof(HubServiceInvoker <>).MakeGenericType(serviceT); var serviceInvokerTMethod = serviceInvokerT.GetMethod("InvokeService"); var serviceCompileInvokerTMethod = serviceInvokerT.GetMethod("CompileInvoker"); var serviceInvokerTInstance = Activator.CreateInstance(serviceInvokerT, "id", "password"); // Expression Type Params var serviceTParam = Expression.Parameter(serviceT, "proxy"); var methodCall = Expression.Call(serviceTParam, serviceT.GetMethod(workOutMessage.methodName), Expression.Constant(workOutMessage.methodArgs[0])); serviceInvokerTMethod.Invoke(serviceInvokerTInstance, new object[] { serviceCompileInvokerTMethod.Invoke(serviceInvokerTInstance, new object[] { methodCall, serviceTParam }) }); }