Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="method"></param>
 /// <param name="handler"></param>
 protected void AddStructMethod <TRequest, TResponse>(Method <TRequest, TResponse> method, StructClientStreamingServerMethod <TRequest, TResponse> handler)
 {
     m_Service = m_Service.AddStructMethod(method, handler);
 }
        /// <summary>
        /// Adds a definition for a client streaming method without type restrictions.
        /// </summary>
        /// <typeparam name="TRequest">The type of the request.</typeparam>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="builder"></param>
        /// <param name="method"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public static ServerServiceDefinition.Builder AddStructMethod <TRequest, TResponse>(this ServerServiceDefinition.Builder builder, Method <TRequest, TResponse> method, StructClientStreamingServerMethod <TRequest, TResponse> handler)
        {
            async Task <byte[]> func(IAsyncStreamReader <byte[]> requestStream, ServerCallContext context)
            {
                TResponse response = await handler(
                    requestStream.Convert(method.RequestMarshaller.Deserializer)
                    , context
                    ).ConfigureAwait(false);

                return(method.ResponseMarshaller.Serializer(response));
            };

            return(builder.AddMethod(s_StructMethodCache.GetMethod(method), func));
        }