示例#1
0
        public async Task <object> CallAsync(MethodInfo methodInfo, Func <object, Task> callback, CancellationToken token, Stream stream, params object[] pureArgs)
        {
            var call = await _factory.CreateAsync(_timeoutInterval);

            await call.StartAsync();

            //stream
            var contractMethod = _contract.Methods.Find(i => i.MethodInfo == methodInfo);
            var instanceMethod = new InstanceMethod(methodInfo);
            var methodContext  = new MethodContext(contractMethod, instanceMethod);
            var readStream     = GetReadStream(stream);
            var clientContext  = new ClientActionExecutingContext(_clientProxyId, _serviceProvider, _optionsName, call, instanceMethod, callback, token, _contract,
                                                                  contractMethod, readStream, pureArgs);

            //header
            var header = AdditionHeader;

            if (header != null && header.Count > 0)
            {
                foreach (var key in header.Keys)
                {
                    clientContext.Header.Add(key, header[key]);
                }
            }

            if (_middlewareBuilder != null)
            {
                await _middlewareBuilder.InvokeAsync(clientContext);

                return(clientContext.Result);
            }

            //onceTransfer will dispose after stream translate finished in OnceCall.
            return(await call.CallAsync(header, methodContext, callback, token, stream, pureArgs));
        }
示例#2
0
文件: Call.cs 项目: ErgEnn/NetRpc
        public async Task <object?> CallAsync(MethodInfo methodInfo, Func <object?, Task>?callback, CancellationToken token, Stream?stream,
                                              params object?[] pureArgs)
        {
            //merge header
            var mergeHeader = MergeHeader(AdditionHeader, _actionExecutingContextAccessor.Context?.Header);

            //start
            var call = await _factory.CreateAsync(_timeoutInterval);

            await call.StartAsync(GetAuthorizationToken(mergeHeader));

            //stream
            var contractMethod = _contract.Methods.First(i => i.MethodInfo == methodInfo);
            var instanceMethod = new InstanceMethod(methodInfo);
            var readStream     = GetReadStream(stream);
            var clientContext  = new ClientActionExecutingContext(_clientProxyId, _serviceProvider, _optionsName, call, instanceMethod, callback, token,
                                                                  _contract, contractMethod, readStream, mergeHeader, pureArgs);

            //invoke
            //onceTransfer will dispose after stream translate finished in OnceCall.
            await _middlewareBuilder.InvokeAsync(clientContext);

            return(clientContext.Result !);
        }