public DaprActorProxyAuthenticateContext( DaprHttpClientHandler handler, DaprActorConfiguration remoteService, string remoteServiceName) { Handler = handler; RemoteService = remoteService; RemoteServiceName = remoteServiceName; }
private async Task MakeRequestAsync( IAbpMethodInvocation invocation, ActorProxyFactory proxyFactory, DaprActorConfiguration configuration ) { var actorId = new ActorId(configuration.ActorId); var invokeType = typeof(TService); // 约定的 RemoteServiceAttribute 为Actor名称 var remoteServiceAttr = invokeType.GetTypeInfo().GetCustomAttribute <RemoteServiceAttribute>(); var actorType = remoteServiceAttr != null ? remoteServiceAttr.Name : invokeType.Name; try { // 创建强类型代理 var actorProxy = proxyFactory.CreateActorProxy <TService>(actorId, actorType); // 远程调用 var task = (Task)invocation.Method.Invoke(actorProxy, invocation.Arguments); await task; // 存在返回值 if (!invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty()) { // 处理返回值 invocation.ReturnValue = typeof(Task <>) .MakeGenericType(invocation.Method.ReturnType.GenericTypeArguments[0]) .GetProperty(nameof(Task <object> .Result), BindingFlags.Public | BindingFlags.Instance) .GetValue(task); } } catch (ActorMethodInvocationException amie) // 其他异常忽略交给框架处理 { if (amie.InnerException != null && amie.InnerException is ActorInvokeException aie) { // Dapr 包装了远程服务异常 throw new AbpDaprActorCallException( new RemoteServiceErrorInfo { Message = aie.Message, Code = aie.ActualExceptionType } ); } throw; } }