2

私はいくつかの ServiceStack デモとサンプル コードをいじっており、URL に project.serviceclass 名を含める必要をなくす方法があるかどうかを確認しようとしています。nuget パッケージを使用して、MvcMovieApp という ASP.NET MVC アプリケーションを作成し、.NET という SS サービスを作成しましたMovieService

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

したがって、応答を得るには、次のように要求する必要があります。

localhost/api/MvcMovieApp.MovieService/Movie/MyMovie

しかし、私は要求を行うことができるようにしたいです

localhost/api/ムービー/マイムービー

これを行う方法はありますか?

アップデート

<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 API を適切に呼び出せるようになりました。これが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
}

私が間違ったことをしたアイデアはありますか?ありがとう

4

1 に答える 1

1

httpHandlersセクションは、構成ファイルごとに1回だけ表示できます。また、場所のサブアイテムである場合は、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>
于 2012-10-25T13:32:28.957 に答える