代码之家  ›  专栏  ›  技术社区  ›  Michael Shimmins

在路由路径上公开属于MVC应用程序中某个区域的WCF服务

  •  14
  • Michael Shimmins  · 技术社区  · 15 年前

    TestService.svc 坐在里面 services MVC应用程序中区域的目录。此区域合并到主应用程序中。这个地区叫做 content

    路线已经布置好,这个地区运转良好。访问 Index 对…采取行动 Home 控制器我可以:

    http://my-host/areas/content/index/home

    http://my-host/content/index/home

    http://my-host/areas/content/services/TestService.svc

    URL必须包含 areas 目录,我不能直接通过 http://my-host/content/services/TestService.svc . 如果我尝试,我会得到一个错误404。

    是否有方法设置应用程序,使其通过与控制器相同的路由表路由SVC请求?我不想用 地区

    1 回复  |  直到 15 年前
        1
  •  24
  •   James Webster Jonathan Wood    14 年前

    如果您有权使用.NET4.0,您可以考虑通过 ServiceRoute 而不是通过.svc文件。

    这将使您能够避免在TestService.svc.cs文件后面包含TestService.svc.cs代码。在Global.asax.cs中,您将拥有以下内容:

    public static void RegisterRoutes(RouteCollection routes, IUnityContainer container)
    {
        ... other MVC route mapping ....
        routes.Add(new ServiceRoute("TestService", new ServiceHostFactory(), typeof(LoaEvents)));
    }
    

    您的服务应该可以通过 http://my-host/TestService

    你也许可以改变 "TestService" 论证 "/content/services/TestService" 或者更能满足你需要的东西。