2012-10-24 120 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> 
相关问题