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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
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. : )
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.
There's a generic WebAPI client to be found here:
https://github.com/CamSoper/CamTheGeek
It's not a proxy, as requested, but it does fill the gap.
Here's the source code: