Esempio n. 1
0
        /// <summary>
        /// Creates the RPC method description.
        /// </summary>
        /// <typeparam name="TRequest">The type of the request.</typeparam>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="builder">The service builder.</param>
        /// <param name="serviceName">The service name.</param>
        /// <param name="handler">The method information.</param>
        /// <param name="marshallerFactory">The factory of the marshaller.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <returns>The method description.</returns>
        private static ServerServiceDefinition.Builder AddStructMethodCore <TRequest, TResponse>(ServerServiceDefinition.Builder builder, string serviceName, RpcMethodHandlerInfo handler, IRpcMarshallerFactory marshallerFactory, object serviceInstance)
        {
            Method <TRequest, TResponse> method = new Method <TRequest, TResponse>(handler.MethodType, serviceName, handler.Handler.Name, marshallerFactory.GetMarshaller <TRequest>(), marshallerFactory.GetMarshaller <TResponse>());

            switch (handler.MethodType)
            {
            case MethodType.Unary:
                return(builder.AddStructMethod(method, (StructUnaryServerMethod <TRequest, TResponse>)handler.Handler.CreateDelegate(typeof(StructUnaryServerMethod <TRequest, TResponse>), serviceInstance)));

            case MethodType.ClientStreaming:
                return(builder.AddStructMethod(method, (StructClientStreamingServerMethod <TRequest, TResponse>)handler.Handler.CreateDelegate(typeof(StructClientStreamingServerMethod <TRequest, TResponse>), serviceInstance)));

            case MethodType.ServerStreaming:
                return(builder.AddStructMethod(method, (StructServerStreamingServerMethod <TRequest, TResponse>)handler.Handler.CreateDelegate(typeof(StructServerStreamingServerMethod <TRequest, TResponse>), serviceInstance)));

            case MethodType.DuplexStreaming:
                return(builder.AddStructMethod(method, (StructDuplexStreamingServerMethod <TRequest, TResponse>)handler.Handler.CreateDelegate(typeof(StructDuplexStreamingServerMethod <TRequest, TResponse>), serviceInstance)));

            default:
                return(builder);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Creates the RPC method description.
 /// </summary>
 /// <typeparam name="TRequest">The type of the request.</typeparam>
 /// <typeparam name="TResponse">The type of the response.</typeparam>
 /// <param name="serviceName">The service name.</param>
 /// <param name="handler">The method information.</param>
 /// <param name="marshallerFactory">The factory of the marshaller.</param>
 /// <returns>The method description.</returns>
 private static Method <TRequest, TResponse> CreateMethodCore <TRequest, TResponse>(string serviceName, RpcMethodHandlerInfo handler, IRpcMarshallerFactory marshallerFactory)
 {
     return(new Method <TRequest, TResponse>(handler.MethodType, serviceName, handler.Handler.Name, marshallerFactory.GetMarshaller <TRequest>(), marshallerFactory.GetMarshaller <TResponse>()));
 }
Esempio n. 3
0
 /// <summary>
 /// Creates the RPC method description.
 /// </summary>
 /// <param name="builder">The service builder.</param>
 /// <param name="serviceName">The service name.</param>
 /// <param name="handler">The method information.</param>
 /// <param name="marshallerFactory">The factory of the marshaller.</param>
 /// <param name="serviceInstance">The service instance.</param>
 /// <returns>The method description.</returns>
 public static ServerServiceDefinition.Builder AddMethod(ServerServiceDefinition.Builder builder, string serviceName, RpcMethodHandlerInfo handler, IRpcMarshallerFactory marshallerFactory, object serviceInstance)
 {
     if (handler.RequestType.IsClass && handler.ResponseType.IsClass)
     {
         MethodInfo m = typeof(RpcReflection).GetMethod("AddMethodCore", BindingFlags.Static | BindingFlags.NonPublic);
         return((ServerServiceDefinition.Builder)m.MakeGenericMethod(new Type[] { handler.RequestType, handler.ResponseType }).Invoke(null, new object[] { builder, serviceName, handler, marshallerFactory, serviceInstance }));
     }
     else
     {
         MethodInfo m = typeof(RpcReflection).GetMethod("AddStructMethodCore", BindingFlags.Static | BindingFlags.NonPublic);
         return((ServerServiceDefinition.Builder)m.MakeGenericMethod(new Type[] { handler.RequestType, handler.ResponseType }).Invoke(null, new object[] { builder, serviceName, handler, marshallerFactory, serviceInstance }));
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Creates the RPC method description.
        /// </summary>
        /// <param name="serviceName">The service name.</param>
        /// <param name="handler">The method information.</param>
        /// <param name="marshallerFactory">The factory of the marshaller.</param>
        /// <returns>The method description.</returns>
        public static IMethod CreateMethod(string serviceName, RpcMethodHandlerInfo handler, IRpcMarshallerFactory marshallerFactory)
        {
            MethodInfo m = typeof(RpcReflection).GetMethod("CreateMethodCore", BindingFlags.Static | BindingFlags.NonPublic);

            return((IMethod)m.MakeGenericMethod(new Type[] { handler.RequestType, handler.ResponseType }).Invoke(null, new object[] { serviceName, handler, marshallerFactory }));
        }