Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't we add a Web API as a "service reference" in Visual Studio the same way we can with WCF or 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?

like image 236
Mike Marks Avatar asked Sep 11 '13 14:09

Mike Marks


People also ask

How do I add a Web service reference in Visual Studio 2019 .NET core?

In Solution Explorer, right-click the name of the project to add the Web service to and then click Add Web Reference. The Add Web Reference dialog box is displayed. In the URL box, enter the URL of the Web service to use. If you do not know the URL, use the links in the browse pane to locate the Web service you want.


2 Answers

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. : )

like image 83
Slack Shot Avatar answered Sep 23 '22 10:09

Slack Shot


why doesn't a Web API support being added as a reference the same way a WCF or ASMX is added

WCF or ASMX-based web services are SOAP-based and there typically is an associated WSDL. WSDL allows tooling to be built around to generate proxy classes and all that but ASP.NET Web API is meant to build REST (or HTTP based) services and there is no meta data in the form of WSDL or anything similar and hence adding service reference through VS is not applicable for ASP.NET Web API. WADL (Web Application Description Language) is supposed to be the WSDL for REST but that spec went no where.

like image 20
Badri Avatar answered Sep 22 '22 10:09

Badri