我開始考慮使用ServiceStack以及用基於ServiceStack的方法替換RiaServices的可能性。無論如何,我們已經使用了一個Dto,並在後端使用NH。我通過添加一個指向「api」而不是應用程序根目錄(Silverlight)的元素來修改webconfig,創建了服務,定義了路由等。我可以打localhost:12543/api/metadata,並獲得列出的操作。當我點擊操作時,它爲我提供了操作「api/certificates」的可用路徑。如果我使用Firefox的休息客戶端插件,我可以擊中http://localhost:12543/api/json/reply/CertificateDefinitionList
,並獲得預期的數據。但是,如果我做http://localhost:12543/api/certificates
我得到404錯誤,並在提琴手說,「處理器的請求未找到」。我錯過了什麼?ServiceStack:對路線感到困惑
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");
}
你定義什麼定製路由? I,E。你爲'/ certificates'定義了一個嗎? – mythz 2013-03-21 22:08:43
我的「錯誤」是在Global.asax中,因爲我將路由定義爲/ api/certificates,但它看起來只需要/證書 – epitka 2013-03-22 12:53:19