为什么我们不能添加一个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?

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

问题描述

我已经决定要使用的Web API(作为中间层)为应用我发展,但似乎无法弄清楚如何在比分扳成到前端(前端是一个ASP .NET MVC4项目)。通常情况下,我只想在前端右键单击服务,选择添加服务引用,并把我的服务的URL。但使用Web API,我不能这样做。什么是创建一个客户端代理类从我的Web API的一些选项要在我的前端使用,为什么不添加一个Web API支持作为参照相同的方式WCF或添加ASMX?

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?

推荐答案

你的意思是一个休息Web服务?休息,没有服务定义页面,就像WCF或ASMX。通常人们想使用一个JSON REST API ..但是..如果你只是寻找一个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天全站免登陆