Katana没有找到使用反射的启动方法

时间:2015-04-19 00:10:42

标签: reflection owin katana

我正在研究Scott Allen关于Pluralsight的MVC 5基础课程

以下代码应该可以使用,但是当我浏览到localhost时:8080我得到一个空白页

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Owin.Hosting;
using Owin;
namespace ConsoleApplication1
{
    using AppFunc = Func<IDictionary<string, object>, Task>;
    class Program
    {
        static void Main(string[] args)
        {
            string uri = "http://localhost:8080";
            using (WebApp.Start<Startup>(uri))   // Katana Please start, using the configuration from the Startup class and listening on the port given by the uri
            {
                Console.WriteLine("Started!");
                Console.ReadKey();
                Console.WriteLine("Stopping!");
            }
        }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Use<HelloWorldComponent>();
        }
    }

    public class HelloWorldComponent
    {
        AppFunc _next;
        public HelloWorldComponent(AppFunc next)
        {
            _next = next;
        }

        // Katana uses reflection to find this Invoke function that matches the AppFunc signature
        public Task Invoke(IDictionary<string, object> environment)
        { 
            var response = environment["owin.ResonseBody"] as Stream;

            using (var writer = new StreamWriter(response))
            {
                return writer.WriteAsync("Hello");
            }
        }
    }
}

我如何让它运作?

1 个答案:

答案 0 :(得分:2)

一切都设置正确,获取响应对象只有一个小错误:

 var response = environment["owin.ResponseBody"] as Stream;

 using (var writer = new StreamWriter(response))
 {
    return writer.WriteAsync("Hello");
 }

注意&#34; p&#34;在&#34; ResponseBody&#34;!