public void RegisterServerType(params Type[] serverType) { foreach (var item in serverType) { ServerAssemblyUtil.InstallType(item); } }
/// <summary> /// 请求处理 /// </summary> /// <param name="remotingRequest"></param> /// <returns></returns> public RemotingResponse HandleRequest(RemotingRequest remotingRequest) { var requestMethodInfo = DependencyManage.Resolve <IMethodCallSerializer>().Deserialize <RpcMethodCallInfo>(remotingRequest.Body); var classType = ServerAssemblyUtil.GetType(requestMethodInfo.TypeName); using (var scope = DependencyManage.BeginLeftScope()) { var obj = scope.Resolve(classType); MethodInfo executeMethodInfo = null; try { LogUtil.InfoFormat("Begin Deal Rpc Request:{0}-{1}", requestMethodInfo.TypeName, requestMethodInfo.MethodName); executeMethodInfo = ServerAssemblyUtil.GetMethod(requestMethodInfo.MethodName, classType) as MethodInfo; if (executeMethodInfo == null) { _rpcMonitor.AddError(new RpcMonitorRequestErrorInfo(requestMethodInfo, remotingRequest, "Not Found Method")); return(remotingRequest.CreateNotFoundResponse($"{requestMethodInfo.TypeName},{requestMethodInfo.MethodName}")); } else { var delegateType = executeMethodInfo.GetMethodReturnType(); OnActionExecuting(executeMethodInfo, requestMethodInfo.Parameters); var executeResult = executeMethodInfo.Invoke(obj, requestMethodInfo.Parameters); RemotingResponse remotingResponse; if (delegateType == MethodType.SyncAction) { remotingResponse = remotingRequest.CreateSuccessResponse(ResponseUtil.NoneBodyResponse); } else if (delegateType == MethodType.SyncFunction) { remotingResponse = remotingRequest.CreateSuccessResponse(GetBody(executeResult, executeMethodInfo)); } else if (delegateType == MethodType.AsyncAction) { var task = (Task)executeResult; task.Wait(); remotingResponse = remotingRequest.CreateSuccessResponse(ResponseUtil.NoneBodyResponse); } else { var resultType = executeMethodInfo.ReturnType.GetGenericArguments()[0]; var mi = HandleAsyncMethodInfo.MakeGenericMethod(resultType); var result = mi.Invoke(this, new[] { executeResult }); remotingResponse = remotingRequest.CreateSuccessResponse(GetBody(result, executeMethodInfo)); } LogUtil.InfoFormat("Rpc Method Dealed:{0}-{1}", requestMethodInfo.TypeName, requestMethodInfo.MethodName); OnActionExecuted(executeMethodInfo); return(remotingResponse); } } catch (Exception e) { _rpcMonitor.AddError(new RpcMonitorRequestErrorInfo(requestMethodInfo, remotingRequest, e)); HandleException(executeMethodInfo, e); return(remotingRequest.CreateDealErrorResponse()); } } }
public void RegisterServerAssembly(Assembly assembly) { ServerAssemblyUtil.InstallAssembly(assembly); }