How to add link for OData v4 endpoint using asp.net web api 2.2 to mvc client application

I am new to web api. I created an OData v4 endpoint using ASP.NET ASP.NET 2.2 using VS 2013. I followed this article http://www.asp.net/web-api/overview/odata-support-in-aspnet-web -api / odata-v4 / create-an-odata-v4-endpoint . It works great. (tried and violinist)

Service sector: -------------------------------------------- --- --------------------

{
  "@odata.context":"http://localhost:57549/odata/$metadata","value":[
    {
      "name":"Courses","kind":"EntitySet","url":"Courses"
    },{
      "name":"Departments","kind":"EntitySet","url":"Departments"
    }
  ]
}

      

Client side: -------------------------------------------- --- ---------------------

I now have an MVC client application (in VS 2012) to which I want to add a service reference for my OData v4 endpoint. I tried using the support link, but it throws the following error (I followed this article: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata- v3 / calling-an-odata-service-from-a-net-client ):

There was an error downloading 'http://localhost:57549/odata/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost:57549/odata'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
If the service is defined in the current solution, try building the solution and adding the service reference again.

      

I'm not sure how to add a web api2.2 link to an MVC client application. How do I resolve the above error? Is it possible to add an Odata endpoint (using asp.net web api 2.2) via the Add Service link?

Thank,

+3


source to share


1 answer


To add a reference to OData V4 you have to use OData V4 Client Code Generator instead of Add Service Reference as the latter only supports OData V1-3.

The proxy generated from both tools is very similar. The team has invested a lot in maintaining API consistency.

Below are a few guides for quickly building up a tool:



http://blogs.msdn.com/b/odatateam/archive/2014/03/12/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspx

http://blogs.msdn.com/b/odatateam/archive/2014/07/09/odata-client-code-generator-2-0-0-release.aspx

http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-client-app

+3


source







All Articles