我将 Servicestack 3.9.59 与 Servicestack.Razor 一起用作独立的控制台程序。
我的请求/响应/服务看起来像:
namespace Info
{
[Route("/OverView")]
public class OverViewRequest : IReturn<OverViewResponse>
{}
public class OverViewResponse
{
public string Name { get; set; }
}
public class OverViewService : Service
{
public OverViewResponse Get(OverViewRequest request)
{
return new OverViewResponse() { Name = "test" };
}
}
}
视图页面如下所示:
@inherits ViewPage<OverViewResponse>
@Model.Name
使用 _Layout 页面:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-theme.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="/static/js/html5shiv.js"></script>
<script src="/static/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
@RenderBody()
</body>
</html>
我的apphost配置如下:
namespace Info
{
class AppHost : AppHostHttpListenerBase
{
public AppHost() : base("Server Info", typeof(AppHost).Assembly) { }
public override void Configure(Container container)
{
Plugins.Add(new RazorFormat());
Config.DefaultRedirectPath = "/OverView";
Config.DebugMode = true;
}
static void Main(string[] args)
{
var appHost = new AppHost();
appHost.Init();
appHost.Start("http://*:2001/");
Thread.Sleep(Timeout.Infinite);
}
}
}
我尽力匹配 RazorRockstars 上的示例但是当我运行程序时,我在控制台上得到以下输出:
at ServiceStack.Razor.Managers.RazorViewManager.TrackPage(IVirtualFile file)
at ServiceStack.Common.Extensions.EnumerableExtensions.ForEach[
T
](IEnumerable`1 values,
Action`1 action)
at ServiceStack.Razor.RazorFormat.Init()
at ServiceStack.Razor.RazorFormat.Register(IAppHost appHost)
在我的浏览器中访问该页面仅显示由 ServiceStack 页面生成的 OverViewRequest 的快照。