我开始研究 ServiceStack 以及用基于 ServiceStack 的方法替换 RiaServices 的可能性。无论如何,我们已经为每个视图使用了一个 Dto,并在后端使用了 NH。我通过添加一个指向“api”而不是应用程序根目录(Silverlight)的元素来修改 webconfig,创建服务,定义路由等。我可以点击 localhost:12543/api/metadata 并列出操作。当我单击操作时,它为我提供了操作“api/certificates”的可用路径。如果我使用 Firefox 的 rest 客户端插件,我可以点击http://localhost:12543/api/json/reply/CertificateDefinitionList
并获得预期的数据。但是,如果我这样做了,http://localhost:12543/api/certificates
我会收到 404 错误,并且在提琴手中它会说“未找到请求的处理程序”。我错过了什么?
HTTP/1.1 404 Not Found
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 21 Mar 2013 19:44:07 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ServiceStack/3.942 Win32NT/.NET
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 1316
Connection: Close
Handler for Request not found:
Request.ApplicationPath: /
Request.CurrentExecutionFilePath: /api/certificates
Request.FilePath: /api/certificates
Request.HttpMethod: GET
在 Web.config 中
<!-- service stack hosting at custom path-->
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>
全球.asax
public override void Configure(Funq.Container container)
{
//this is because ria entry for system.webserver makes it not work for
// service stack
SetConfig(new EndpointHostConfig
{
ServiceStackHandlerFactoryPath = "api",
});
container.RegisterAutoWired<ComplianceService>();
Routes.Add<CertificateDefinitionList>("/api/certificates");
}