Last post Oct 15, 2014 09:48 AM by coolkushi1221
Oct 01, 2014 03:36 PM|coolkushi1221|LINK
I am new to web api. I have created an OData v4 endpoint using asp.net web API 2.2 using VS 2013. I have followed this article http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint.
It's working fine. (tested through fiddler also)
Now I have MVC client application (in VS 2012) to which I want to add service reference for my OData v4 Endpoint. I have tried using add service reference but it throws following error (I have 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.
How to resolve above error? Is that possible to add Odata endpoint (using asp.net web api 2.2) through Add Service Reference?
Oct 02, 2014 02:31 AM|Rajneesh Verma|LINK
Can you host your service in local iis and then try...
For service testing you can use
Oct 02, 2014 04:45 AM|damienBod|LINK
Use the OData V4 code generator instead. You have an OData V4 service, not a V3 service.
Oct 02, 2014 09:35 AM|coolkushi1221|LINK
I have hosted my service in local IIS and tried but it didn't work. It is throwing me same error.
When I was creating my service, I have picked empty MVC web application project template and just followed following link to create the endpoints:
I have researched online and found people are saying that we can't add web api through add service reference because it is REST or HTTP. And I have found following article on asp.net site which says we can add service using add service reference ( http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/calling-an-odata-service-from-a-net-client ).
Only difference is I am using v4 and this article is for v3 protocol. Is that a difference?
Both above statements are conflicts to each other. Not sure what is right?
Oct 02, 2014 09:36 AM|coolkushi1221|LINK
How does protocol make a difference here? I am trying to understand..
Oct 02, 2014 03:08 PM|damienBod|LINK
OData V3 and OData V4 are not compatible in any way, almost nothing to do with each other. Either you use V3 or you use V4. A V3 client cannot work with a V4 server
Oct 02, 2014 05:20 PM|coolkushi1221|LINK
I have followed your suggested article http://damienbod.wordpress.com/2014/07/09/web-api-odata-v4-using-an-odata-t4-generated-client-part-8/.
Everything is looking good but I am getting few errors when I build the client application.
Error in T4 .cs file:
Error 2 The type or namespace name 'Edm' does not exist in the namespace 'Microsoft.OData' (are you missing an assembly reference?)
Code where an error is getting generated in T4 .cs file:
private abstract class GeneratedEdmModel
private static global::Microsoft.OData.Edm.IEdmModel ParsedModel = LoadModelFromString();
private const string Edmx = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
In my client references folder, I have Microsoft.OData.Client (v18.104.22.168) and Microsoft.OData.EntityFrameworkProvider (v 22.214.171.124). I don't have Microsoft.OData.Edm in my client references.
What should I do?
Oct 03, 2014 12:37 AM|damienBod|LINK
Here's a list of NuGet packages I have after installing from NuGet. If your missing one, install it.
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
<package id="Microsoft.OData.Client" version="6.6.0" targetFramework="net45" />
<package id="Microsoft.OData.Core" version="6.6.0" targetFramework="net45" />
<package id="Microsoft.OData.Edm" version="6.6.0" targetFramework="net45" />
<package id="Microsoft.Spatial" version="6.6.0" targetFramework="net45" />
You could compare your client to this one:
It should also work with the latest packages, but I havn't tried that yet.
hope this helps
Oct 03, 2014 02:44 AM|Rajneesh Verma|LINK
See if helpful
Oct 03, 2014 11:17 AM|coolkushi1221|LINK
I have tried to install all required packages but it keeps throwing following error:
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.2.2)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.OData.Core (≥ 6.5.0 && < 7.0.0)'.
Attempting to resolve dependency 'Microsoft.Spatial (= 6.5.0)'.
Attempting to resolve dependency 'Microsoft.OData.Edm (= 6.5.0)'.
Successfully installed 'Newtonsoft.Json 6.0.5'.
Successfully installed 'Microsoft.AspNet.WebApi.Client 5.2.2'.
Successfully installed 'Microsoft.AspNet.WebApi.Core 5.2.2'.
Successfully installed 'Microsoft.Spatial 6.5.0'.
Successfully installed 'Microsoft.OData.Edm 6.5.0'.
Successfully installed 'Microsoft.OData.Core 6.5.0'.
Successfully installed 'Microsoft.AspNet.OData 5.3.1-beta'.
Successfully added 'Newtonsoft.Json 6.0.5' to MyCollegeWebApplication.
Executing script file 'C:\Workspace\POC\MyCollegeWebApplication\packages\Newtonsoft.Json.6.0.5\tools\install.ps1'.
Successfully added 'Microsoft.AspNet.WebApi.Client 5.2.2' to MyCollegeWebApplication.
Successfully added 'Microsoft.AspNet.WebApi.Core 5.2.2' to MyCollegeWebApplication.
Successfully uninstalled 'Microsoft.Spatial 6.5.0'.
Successfully uninstalled 'Microsoft.AspNet.WebApi.Core 5.2.2'.
Successfully uninstalled 'Microsoft.AspNet.WebApi.Client 5.2.2'.
Successfully uninstalled 'Newtonsoft.Json 6.0.5'.
Install failed. Rolling back...
Could not install package 'Microsoft.Spatial 6.5.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author.
I have tried with .NETFramework, version=v4.5.1 also, but it is complaining the same. I am using VS 2012 to create my client web application. (I have created OData v4 end points service in VS 2013. ) Is VS 2012 creating the issue?
Also I would like to know how to find out which assembly references package contains?
Oct 03, 2014 01:38 PM|coolkushi1221|LINK
There was an update for Nuget Package Manager. I figured that out from VS 2012 -->Tools --> Extensions and Updates..--> Updates
Now I am able to add those packages. I will consume that service with client and let you know.
Oct 15, 2014 09:48 AM|coolkushi1221|LINK
I am using OData V3 Actions with web api 2.2. But somehow It's not working. Could you please look at the issue at ticket http://forums.asp.net/p/2013087/5791519.aspx?OData+V3+action+in+ASP+NET+web+api+doesn+t+get+trigger+