如何在 ASP.Net MVC3 应用程序中托管 WCF 数据服务
我编写了几个 WCF 数据服务,发现它们非常有用。然而,我发现路由非常痛苦。我看到一些对话表明您可以在 ASP.Net MVC 应用程序中托管数据服务(我一直使用 ASP.Net 网站)。但是,我似乎找不到任何如何实现这一目标的例子。有人有任何我可以查看或建议的参考资料吗?
I have written several WCF data services and find them quite useful. However, I have found routing to be quite a pain. I have seen conversations that indicate that you can host a data service in an ASP.Net MVC app (I have always used ASP.Net web sites). However, I do not seem to be able to find any examples of how to achieve this. Does anybody have any references I could check-out or advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题是前一段时间发布的,但我认为仍然有人对在 ASP.NET MVC 项目中使用 WCF 数据服务感兴趣。
假设您的项目中有一个名为“DataSourceService.svc”的服务,您可以通过在“RouteConfig.cs”中配置路由来在 MVC 项目中使用此服务,如下所示:
确保您在 Web.config 中具有以下配置:
现在您可以通过在浏览器中运行您的项目并使用以下 url 来检查一切是否正常:
http://localhost:port_number/DataSourceService/$metadata
... 这应该返回您的元数据。
The question was posted some time ago but I assume there are still people interested in using WCF Data Services in ASP.NET MVC projects.
Assuming that you have in your project a service called: 'DataSourceService.svc' you can use this service in an MVC project by configuring the routing in 'RouteConfig.cs' as follows:
Make sure that you have in Web.config the following configuration:
Now you can check that everything works fine by running your project in the browser and using the following url:
http://localhost:port_number/DataSourceService/$metadata
... which should return your metadata.
WCF Web api 可能可以满足您的需求。这是他们的入门页面 。您可以将服务托管在 MVC 应用程序内部,甚至可以连接到 MVC 使用的相同路由。
The WCF web api may do what you're looking for. Here's their getting started page. You host the service inside of the MVC app, and even hook into into the same routing that MVC uses.