protected override void OnInvokeMethod(InvocationContext context) { var method = context.Method as MethodInfo; ServiceInvoke info = new ServiceInvoke { Id = Guid.NewGuid(), Name = ServiceName, Action = context.Method.Name, Arguments = context.Arguments, Instance = Instance, DestUserId = UserId, }; Type returnType = method.ReturnType; if (typeof(Task).IsAssignableFrom(returnType)) { Type type = returnType.GetGenericArguments()[0]; context.Return = ServiceClientHandler.GetType() .GetMethod("InvokeTaskAsync2") .MakeGenericMethod(type) .Invoke(ServiceClientHandler, new object[] { info }); } else { context.Return = ServiceClientHandler.Invoke(info); } }
public ServiceProxy(Type type, ServiceClientHandler serviceHandler, string serviceName, string userId, string instance = null) : base(type) { ServiceClientHandler = serviceHandler; ServiceName = serviceName; UserId = userId; Instance = instance; ServiceClientHandler.Raised += ServiceHandler_Raised; }