2012-10-24 93 views
2

我在玩一些ServiceStack演示和示例代碼,並試圖查看是否有辦法刪除需要在項目中使用project.serviceclass名稱的方法網址。我使用nuget包並創建了一個名爲MvcMovieApp的ASP.NET MVC應用程序,並創建了一個名爲MovieService的SS服務。從servicestack中刪除project.serviceclass名稱url

[Route("/Movie")] 
[Route("/Movie/{Name}")] 
public class Movie 
{ 
    public long Id { get; set; } 
    public string Name { get; set; } 
    public string Description { get; set; } 
    public string Genre { get; set; } 
} 
public class MovieResponse 
{ 
    public string Result { get; set; } 
} 

public class MovieService : Service 
{ 
    public object Any(Movie request) 
    { 
     return new MovieResponse { Result = "The best Movie is " + request.Name }; 
    } 
} 

所以讓我不得不請求的響應:

本地主機/ API/MvcMovieApp.MovieService /電影/ MYMOVIE

,但我希望能夠做出請求

本地主機/ API /電影/ MYMOVIE

有沒有辦法做到這一點?

更新

<httpHandlers> 
    <add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" /> 
</httpHandlers> 
<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> 

更新2:

我能得到它的那種工作。我試圖將ServiceStack與MVC應用程序集成在一起。所以我Application_Start有以下幾點:

protected void Application_Start() 
{ 
    AreaRegistration.RegisterAllAreas(); 
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
    // RouteConfig.RegisterRoutes(RouteTable.Routes); 
} 

註釋掉MVC RouteConfig固定的問題,並讓我打電話給該ServiceStack APIS正常。這裏是RegisterRoutes方法。我有這條線,以便MVC應該忽略所有API。

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

    //routes.MapHttpRoute(
    // name: "DefaultApi", 
    // routeTemplate: "api/{controller}/{id}", 
    // defaults: new { id = RouteParameter.Optional } 
    //); 

    routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}", 
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 
    routes.IgnoreRoute("api/{*pathInfo}"); 
    routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); //Prevent exceptions for favicon 
} 

任何想法我做了什麼錯?謝謝

+0

它應該工作。你可以發佈web.config中處理httpHandler路徑的部分嗎? – kampsj

+0

它應該按預期工作,確保您具有正確的ASP.NET處理程序映射配置,請參閱:http://www.servicestack.net/ServiceStack.Hello/#rootpath – mythz

回答

1

httpHandlers部分每個配置文件只能出現一次。當它是該位置的子項目時,您也不需要在httpHandler中包含path = api *。

只能使用此爲您的配置:

<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> 
相關問題