为什么我们不能添加一个 Web API 作为“服务引用"?在 Visual Studio 中使用 WCF 或 ASMX 的方式相同吗? [英] Why can't we add a Web API as a "service reference" in Visual Studio the same way we can with WCF or ASMX?

查看:19
本文介绍了为什么我们不能添加一个 Web API 作为“服务引用"?在 Visual Studio 中使用 WCF 或 ASMX 的方式相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定将 Web API(作为中间层)用于我正在开发的应用程序,但似乎无法弄清楚如何将其绑定"到前端(前端是 ASP.NET MVC4 项目).通常,我只需右键单击前端的服务,选择添加服务引用",然后将我的服务的 URL 放入.但是使用 Web API,我不能这样做.有哪些选项可以从我的 Web API 创建客户端代理类以在我的前端使用,为什么不像添加 WCF 或 ASMX 一样添加 Web API 支持作为参考?

I've decided to use Web API (as a middle tier) for an app I'm developing, but can't seem to figure out how to "tie it in" to the front end (front end being an ASP.NET MVC4 project). Normally, I would just right click Services on the front end, choose "Add Service Reference", and put the URL for my service in. But with Web API, I can't do that. What are some options for creating a client proxy class off of my Web API to be used on my front end, and why doesn't a Web API support being added as a reference the same way a WCF or ASMX is added?

推荐答案

你的意思是 Rest Web Service?Rest 没有服务定义页面,就像 WCF 或 ASMX 一样.通常人们希望将 Rest API 与 JSON 一起使用……但是……如果您只是在寻找 JSON 输出,并且您希望您的客户端能够快速连接到您的服务,那么您应该考虑 OData.它真的很容易创建,并且它使您的数据层可用于大量客户端语言.他们有为大量语言移植的 OData 客户端库.根据要求作为答案提交.:)

Do you mean a Rest Web Service? With Rest, there is no service definition page, like with WCF or ASMX. Usually people want to use a Rest API with JSON.. however.. if you are just looking for a JSON output, and you want your clients to quickly be able to connect to your service, you should consider OData. It's really easy to create and it makes your data layer accessible for a large number of client languages. They have the OData client library ported for a ton of languages. Submitted as an answer, as requested. : )

这篇关于为什么我们不能添加一个 Web API 作为“服务引用"?在 Visual Studio 中使用 WCF 或 ASMX 的方式相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆