【发布时间】:2016-04-15 21:23:46
【问题描述】:
我正在尝试在 .NET 4.6.1(Visual Studio 2015 Update 2)中使用 Nancy。当我根据下面的代码和参考创建引用 .NET 4.6.1 框架的控制台应用程序时,我在自己的示例 Stub 和 Nancy.Response 之间看到了一个 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException,但从未收到任何 JSON 输出。 Super-Duper-Happy-Path 中是否缺少我的东西?我知道我没有指定视图,但我只是打算使用以下接受标头调用此资源:Accept: application/json。我以“管理员”身份执行 Visual Studio,操作系统是 Windows 7 x64(大部分是最新更新)。
程序.cs:
using System;
namespace SelfHostedTest
{
class Program
{
static void Main(string[] args)
{
var host = new SelfHoster();
host.Create("http://localhost:8002");
Console.WriteLine("Started");
Console.ReadLine();
host.Destroy();
}
}
}
RootModule.cs:
using Nancy;
namespace SelfHostedTest
{
public class Stub
{
public int Number { get; set; }
public string Message { get; set; }
}
public class RootModule : NancyModule
{
public RootModule()
{
Get["/"] = _ => new Stub() {Message = "Hello", Number = 1};
}
}
}
SelfHoster.cs:
using System;
using Nancy;
using Nancy.Hosting.Self;
namespace SelfHostedTest
{
public class SelfHoster
{
private NancyHost _host;
public void Create(string url)
{
_host = new NancyHost(new Uri(url), new DefaultNancyBootstrapper());
_host.Start();
}
public void Destroy()
{
_host?.Stop();
}
}
}
参考资料:
Microsoft.CSharp
Nancy (1.4.3)
Nancy.Hosting.Self (1.4.1)
Nancy.Serialization.JsonNet (1.4.1)
Newtonsoft.Json (8.0.3)
System
System.Core
System.Data
System.Data.DataSetExtensions
System.Net.Http
System.Xml
System.Xml.Linq
我的最终目标是将其放入带有 websockets 的 OWIN 自托管模块中,但我将其剥离回此示例以尝试隔离我的问题。
【问题讨论】:
标签: c# nancy .net-4.6.1