Add service reference to ASP.NET Web API service

Daniel Revell picture Daniel Revell · Jul 13, 2011 · Viewed 13.3k times · Source

I've got an MVC solution that hosts a few routes for Web API services. In some situations, I will call these from JavaScript with a simple HTTP get. In others, I want to call them from some .NET code, perhaps another MVC application.

Is there a way to add a service reference to these Web API endpoints and have the tooling create the proxy client and CLR types as it would do with a typical WCF service? I know there is no SOAP involved here but I did read that it is possible, just not how.

Answer

Ladislav Mrnka picture Ladislav Mrnka · Jul 13, 2011

No it is REST service. REST service doesn't expose metadata for creating proxy by service reference (except WCF Data Services which have some special form of metadata). Use Web-API's HttpClient class to call the service.