Reputation: 21
I tried to understand this tutorial: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
I can generate the proxy without any problems. Just as it is described.
But at chapter "Consume the OData service" it doesn't work. I have named the application and the proxy exactly as shown in the tutorial. How can I make odata available in namespace Microsoft?
I used:
@Evandro Paula:Thank you for your help! I have come a little further thanks to your help. But unfortunately I have not come to the goal yet.
I installed/updated:
Now the results look like this:
Compiling works with Proxy (TrippinProxy.cs), but without Odata example. (Screenshot)
As soon as I copy the code from the tutorial, compiling does't work anymore. (Screenshot)
using System;
using Microsoft.OData.SampleService.Models.TripPin;
namespace TrippinApp
{
class Program
{
static void Main(string[] args)
{
DefaultContainer dsc = new DefaultContainer(
new Uri("http://services.odata.org/V4/(S(fgov00tcpdbmkztpexfg24id))/TrippinServiceRW/"));
var me = dsc.Me.GetValue();
Console.WriteLine(me.UserName);
}
}
}
source: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
Now the Namespace Microsoft.OData is found. But not Microsoft.OData.SampleService (Screenshot)
Upvotes: 2
Views: 3524
Reputation: 41
I had exactly the same problem and user3137104's solution worked for me, but I want to elaborate more on the circumstances since Sebastian Widz's comment suggests some confusion. I was following this Microsoft tutorial on getting started with OData clients. This is with
When researching for this answer, I followed the tutorial exactly and connected to https://services.odata.org/V4/TripPinServiceRW/$metadata
, in which case it worked. The namespace existed:
Microsoft.OData.SampleService.Models.TripPin
and I was able to call:
var context = new DefaultContainer(new Uri(serviceRoot));
Using the default settings when adding the OData Connected Service, these definitions can be found in Reference.cs
. This is missing in OP's screenshot (something might have gone wrong when adding the connected service, but the linked tutorial isn't available anymore, so I can't quite comprehend the original problem).
However, what caused me to end up on this thread, is that I immediately tried to connect to a different endpoint (instead of https://services.odata.org/V4/TripPinServiceRW/$metadata
; I had created my own local server) when following the tutorial and adding an OData Connected Service. Obviously (in hindsight), the above mentioned namespace was not availabe. But, what was more confusing, is that DefaultContainer
was also not available. Instead, I had to call
var context = new Default.Container(new Uri(serviceRoot));
where Default
is a namespace and Container
a class within that namespace defined in Reference.cs
On a side note, Default.Container
is also availabe when using the TripPin sample.
To reiterate, the relevant definitions can be found in Reference.cs
(auto-generated using default values on the OData Connected Servce).
Upvotes: 0
Reputation: 1
I worked with the same example (TripPinService) and got the same error. It looks like there is an error in the sample.
Instead of:
var context = new DefaultContainer(new Uri(serviceRoot));
You need to write:
var context = new Default.Container(new Uri(serviceRoot));
After that code runs without errors
Upvotes: -1
Reputation: 2994
In my case, I deleted the NuGet cache folder, and it compiles now.
%LOCALAPPDATA%\Nuget\v3-cache
Upvotes: 0
Reputation: 2642
First, update the packages you mentioned on your question to their latest version. It looks like Visual Studio didn't use the latest version in your case. I'm using Visual Studio 2017 Enterprise Edition (version 15.7.3) for this test.
Once the packages are up to date, you will observe the following build error, which is related to issue https://github.com/OData/lab/issues/80:
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'EdmxReader' does not exist in the namespace 'Microsoft.OData.Edm.Csdl' (are you missing an assembly reference?) ODataClient C:\temp\NET\ODataClient\Connected Services\TrippingService\TrippingProxy.cs 510 Active
The resolution for this issue is available at https://github.com/juliopinto15/lab/commit/deb1254301a775eb6771b0bed672dd3f56f37cfe.
Just change the proxy (e.g. TrippingProxy.cs) generated code line below as part of method LoadModelFromString():
return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader);
to
return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader);
Upvotes: 2