/// <summary> /// 执行业务 /// </summary> /// <param name="targetMethod">目标方法</param> /// <param name="args">方法参数数组</param> /// <returns>业务返回值</returns> protected override object InvokeBusiness(MethodInfo targetMethod, object[] args) { if (RpcClientMethod == null) { RpcClientMethod = CreateRpcClientMethod(); if (RpcClientMethod == null) { throw new NullReferenceException("找不到Rpc客户端方法对象"); } } var rpcData = new RpcDataInfo() { MethodFullPath = string.Format("{0},{1}.{2}", targetMethod.ReflectedType.Assembly.GetName().Name, targetMethod.ReflectedType.FullName, targetMethod.Name), MethodParams = args }; return(RpcClientMethod.Call(targetMethod, rpcData)); }
/// <summary> /// 执行业务 /// </summary> /// <param name="targetMethod">目标方法</param> /// <param name="args">方法参数数组</param> /// <returns>业务返回值</returns> protected override object InvokeBusiness(MethodInfo targetMethod, object[] args) { var rpcData = new RpcDataInfo() { MethodFullPath = string.Format("{0},{1}.{2}", targetMethod.ReflectedType.Assembly.GetName().Name, targetMethod.ReflectedType.FullName, targetMethod.Name), MethodParams = args }; var inBytes = MessageQueueConfig.BytesSerialization.Serialize(rpcData); byte[] resultBytes = null; using (var rpcClient = MessageQueueConfig.RpcClientFactory.Create()) { resultBytes = rpcClient.Call(inBytes); } // 如果返回值是空或者类型是void,则直接返回null if (resultBytes.IsNullOrLength0() || targetMethod.ReturnType.IsTypeVoid()) { return(null); } else { Type targetType = null; // 判断返回类型是否Task if (targetMethod.ReturnType.IsTypeNotGenericityTask()) { return(null); } else if (targetMethod.ReturnType.IsTypeGenericityTask()) { targetType = targetMethod.ReturnType.GetProperty("Result").PropertyType; } else { targetType = targetMethod.ReturnType; } return(MessageQueueConfig.BytesSerialization.Deserialize(resultBytes, targetType)); } }