2013-03-21 100 views
1

我開始考慮使用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"); 
} 
+1

你定義什麼定製路由? I,E。你爲'/ certificates'定義了一個嗎? – mythz 2013-03-21 22:08:43

+0

我的「錯誤」是在Global.asax中,因爲我將路由定義爲/ api/certificates,但它看起來只需要/證書 – epitka 2013-03-22 12:53:19

回答

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;} 
} 

你也可以用流利的API描述here

當我點擊運行它給我提供的路線操作「API /證書」...但是,如果我做http://localhost:12543/api/certificates我得到404錯誤

如果您看到「GET api/certificates」 'json/metadata?op=Certificate'頁面,這聽起來像你在做[Route("/api/certificates")]。在路由中使用'api'是不必要的,因爲路徑/ url的'api'部分已經在web.config中配置。

**這聽起來像你這樣做在web.config中 - 但參考文獻見here在b)主機服務在/ custompath

<system.web> 
    <httpHandlers> 
    <add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/> 
    </httpHandlers> 
</system.web>