Ejemplo n.º 1
0
        /// <summary>
        /// Invokes a simple remote call asynchronously.
        /// </summary>
        public override AsyncUnaryCall <TResponse> AsyncUnaryCall <TRequest, TResponse>(Method <TRequest, TResponse> method, string host, CallOptions options, TRequest request)
        {
            var content = new PipeContent();
            var message = new HttpRequestMessage(HttpMethod.Post, method.FullName);

            message.Content = content;
            message.Version = new Version(2, 0);

            // Write request body
            var sendTask = SendRequestMessageAsync <TRequest>(
                async() =>
            {
                await content.PipeWriter.WriteMessageCoreAsync(method.RequestMarshaller.Serializer(request), true);
                content.PipeWriter.Complete();
            },
                _client, message);

            return(new AsyncUnaryCall <TResponse>(
                       responseAsync: GetResponseAsync(sendTask, method.ResponseMarshaller.Deserializer),
                       responseHeadersAsync: GetResponseHeadersAsync(sendTask),
                       // Cannot implement due to trailers being unimplemented
                       getStatusFunc: () => new Status(),
                       // Cannot implement due to trailers being unimplemented
                       getTrailersFunc: () => new Metadata(),
                       disposeAction: () => { }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invokes a client streaming call asynchronously.
        /// In client streaming scenario, client sends a stream of requests and server responds with a single response.
        /// </summary>
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(Method <TRequest, TResponse> method, string host, CallOptions options)
        {
            var pipeContent = new PipeContent();
            var message     = new HttpRequestMessage(HttpMethod.Post, method.FullName);

            message.Content = pipeContent;
            message.Version = new Version(2, 0);

            var sendTask = SendRequestMessageAsync <TRequest>(() => Task.CompletedTask, _client, message);

            return(new AsyncClientStreamingCall <TRequest, TResponse>(
                       requestStream: new PipeClientStreamWriter <TRequest>(pipeContent.PipeWriter, method.RequestMarshaller.Serializer, options.WriteOptions),
                       responseAsync: GetResponseAsync(sendTask, method.ResponseMarshaller.Deserializer),
                       responseHeadersAsync: GetResponseHeadersAsync(sendTask),
                       // Cannot implement due to trailers being unimplemented
                       getStatusFunc: () => new Status(),
                       // Cannot implement due to trailers being unimplemented
                       getTrailersFunc: () => new Metadata(),
                       disposeAction: () => { }));
        }