我开始研究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错误,并且在fiddler中它说“找不到请求的处理程序”。我错过了什么?
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>
Global.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");
}
答案 0 :(得分:1)
如果您可以提供更多关于路线的详细信息,请@mythz提出这将有所帮助。
为了浏览http://localhost:12543/api/certificates
,我会创建一个像
[Route("/certificates")] //**this assumes you have a web.config with 'api' as custom path
public class Certificate
{
public string FieldOne {get; set;}
}
您还可以使用描述为here
的Fluent API 当我点击该操作时,它为我提供了“api / certificates”操作的可用路径......但是,如果我http://localhost:12543/api/certificates
我收到404错误
如果您在'json/metadata?op=Certificate'
页面上看到“获取API /证书”,则听起来就像您正在[Route("/api/certificates")]
。在路由中使用'api'是不必要的,因为路径/ url的'api'部分已经在web.config中配置。
**听起来你已经在web.config中完成了这个 - 但是为了参考,参见b下的here)/ custompath上的主机服务
<system.web>
<httpHandlers>
<add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>