예제 #1
0
        public ServiceModule(IServiceMethodLocator serviceMethodLocator)
        {
            foreach (ServiceMethod serviceMethod in serviceMethodLocator.GetServiceMethods())
            {
                ParameterInfo[] parameterInfos = serviceMethod.MethodInfo.GetParameters();

                ServerPath serverPath = ServerPaths.GetServerPath(serviceMethod.AsyncServiceMethodInfo);

                Post[serverPath.SubPath, serverPath.FullPath, true] = async(x, ct) =>
                {
                    Task responseTask = (Task)serviceMethod.MethodInfo.Invoke(
                        serviceMethod.Instance,
                        parameterInfos.Select(CreateParameter).ToArray());

                    object result = await GetTaskResult(responseTask);

                    Response response = JsonConvert.SerializeObject(result);

                    response.ContentType = "application/json";
                    response.StatusCode  = HttpStatusCode.OK;

                    return(response);
                };
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RestServiceHandler"/> class.
        /// </summary>
        /// <param name="serviceContext">The service context.</param>
        /// <param name="methodLocator">The service method locator.</param>
        /// <param name="methodInvoker">The service method invoker.</param>
        public RestServiceHandler(IServiceContext serviceContext, IServiceMethodLocator methodLocator, IServiceMethodInvoker methodInvoker)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            if (methodLocator == null)
            {
                throw new ArgumentNullException("methodLocator");
            }

            if (methodInvoker == null)
            {
                throw new ArgumentNullException("methodInvoker");
            }

            m_serviceContext = serviceContext;
            m_methodLocator = methodLocator;
            m_methodInvoker = methodInvoker;

            ServiceAsyncTimeout = TimeSpan.Zero;
        }