如何在asp.net MVC应用程序中访问虚拟目录中的WCF服务?
我正在尝试在单个网站中部署 asp.net MVC 和 WCF 服务。根站点是 MVC 应用程序,我将运行 WCF 作为站点的虚拟目录。但是,由于 MVC 的路由不会将请求中继到服务,因此无法访问该服务。它会说“找不到页面”。
http://PC:9000 <- mvc 应用程序的根目录
我有一个名为“wcf”的 wcf 虚拟目录,
http://pc:9000/wcf/service.svc <- 应该已访问该服务但 mvc 的路由会介入并显示页面未找到。
知道如何进行这项工作吗?如果呼叫是针对服务的,我如何忽略路由?
I am trying to deploy an asp.net MVC and a WCF service in a single website. The root site is the MVC application and i am going to run the WCF as a virtual directory of the site. However the service cant be accessed since the routing of the MVC would not relay the request to the service. It would say "Page not Found".
http://PC:9000 <- root of mvc application
I have a virtual directory for the wcf named "wcf",
http://pc:9000/wcf/service.svc <- should have accessed the service but routes of the mvc intervened and will display page not found.
Any idea how to make this work? How would i ignore the routing if the call is for the service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加忽略路由:
Try adding an ignore route:
这就是我所做的:
因为根应用程序是 MVC,所以当用户尝试访问虚拟目录中的 WCF 并尝试导航时,MVC 将检测到用户尚未在 WCF 应用程序中进行身份验证。 MVC 将按照 Web 配置的指示将其重新路由到身份验证表单页面。
要解决这个问题,只需在 MVC 的 Web 配置文件中添加以下代码即可。
这意味着禁用 WCF 路径的身份验证。因此,当用户访问 WCF 服务时,不会通知 MVC WCF 尚未经过身份验证,因此不会发生重新路由。
这解决了我的问题。
Here is what i did:
Because the root application is an MVC, when the user tries to access the WCF in the virtual directory and try to navigate, the MVC will detect that the user is not yet authenticated in the WCF app. What the MVC will do is it will reroute it to the authentication form page as directed by the web config.
To solve this, just add the following code on the web config file of the MVC.
What this means is to disable the authentication of the WCF path. So when the user access WCF service, it will not notify the MVC that WCF is not yet authenticated and thus no rerouting occurs.
This solve my problem.