揭露属于MVC中的应用面积在路由路径WCF服务 [英] Expose WCF services that belong to an Area in MVC app at a routed path
问题描述
我有一个WCF服务(可以说 TestService.svc
坐在服务里的区域
目录在MVC应用程序,该区域合并成主要的应用程序。该区域被称为内容
。
I've got a WCF service (lets say TestService.svc
sitting inside the services
directory of an Area in an MVC app. This area is combined into the main app. The area is called content
.
该路线已设置和区域工作正常。要访问首页
控制器上的首页
动作我可以执行:
The routes have been setup and the area works fine. To access the Index
action on the Home
controller I can do either:
的http://我的主机/区域/内容/首页/家居
或
的http://我的主机/内容/索引/家居
SVC的文件却只能通过以下方式访问:
The SVC file however can only be accessed via:
HTTP://my-host/areas/content/services/TestService.svc
URL必须包括地区
目录,我不能直接通过 HTTP访问://我的主机/内容/服务/ TestService.svc
。如果我尝试,我给出错误404。
The URL must include the areas
directory, I can't access it directly via http://my-host/content/services/TestService.svc
. If I try I am given an error 404.
有没有一种方法来设置应用程序,以便通过相同的路由表的控制器SVC请求时,它的路线?我不希望有使用地区
的服务。
Is there a way to setup the application so that it routes the SVC request through the same route table as the controllers? I don't want to have to use areas
for the services.
推荐答案
如果你必须使用.NET 4.0的自由,你可能要考虑提供WCF服务通过<一个href=\"http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.serviceroute.aspx\">ServiceRoute而不是通过一个.svc文件。
If you have the liberty to use .Net 4.0 you might want to consider making your WCF service available via a ServiceRoute rather than via a .svc file.
这将使您避免了TestService.svc.cs code-背后的TestService.svc文件。在你的Global.asax.cs您将有以下内容:
This will enable you to avoid having the TestService.svc file with a TestService.svc.cs code-behind. In your Global.asax.cs you will have the following:
public static void RegisterRoutes(RouteCollection routes, IUnityContainer container)
{
... other MVC route mapping ....
routes.Add(new ServiceRoute("TestService", new ServiceHostFactory(), typeof(LoaEvents)));
}
您服务应然后通过 HTTP可访问://我的主机/ TestService的
您也许能在TestService的
参数更改为/内容/服务/ TestService的
或东西满足您的需求更好地工作。
You might be able to change the "TestService"
argument to "/content/services/TestService"
or something that works better for your needs.
这篇关于揭露属于MVC中的应用面积在路由路径WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!