Search code examples
c#visual-studioasp.net-coreodatasimple.odata.client

Simple.odata.client stops at looking for #metadata


I'm building a client to return data from a V4 oData service. The following code works great in LinqPad v5 and v6. But implementing it in Visual Studio ONLY seems to create the GET request for the #metadata, and then ends.

I'm primarily creating this on Windows 10, but I've also tried it in VS for Mac. It runs but also only creates the GET for the #metadata.

I've created new, clean projects. I've gone back to using the simplest request examples from the frameworks GIT site. I've tried using new projects using .Net Core (2.2 and 3.0), .Net Standard and .Net Framework.

var credentials = new NetworkCredential("username", "password");
var URL = new Uri("http://servername:60080/#########.odata/");
var settings = new ODataClientSettings(URL, credentials)
{
   IgnoreResourceNotFoundException = true,
   OnTrace = (x, y) => Console.WriteLine(string.Format(x, y)),
   PayloadFormat = ODataPayloadFormat.Json,
   IgnoreUnmappedProperties = true,
   RenewHttpConnection = true,
   TraceFilter = ODataTrace.All,
   PreferredUpdateMethod = ODataUpdateMethod.Patch
};

var client = new ODataClient(settings);
var annotations = new ODataFeedAnnotations();

IEnumerable<APPLICATIONS_RAW> packages = await client
       .For<APPLICATIONS_RAW>()
       .Filter(f => f.TIMEFRAME >= convertedStartOffset)
       .Filter(f => f.TIMEFRAME < convertedEndOffset)
       .FindEntriesAsync(annotations);

while (annotations.NextPageLink != null)
{
    countPages++;
    IEnumerable<APPLICATIONS_RAW> packages2 = await client
       .For<APPLICATIONS_RAW>()
       .FindEntriesAsync(annotations.NextPageLink, annotations);

     packages = packages.Concat(packages2);
}

The code typically returns with the following (followed by the data).

GET request: http://servername:60080/#####.odata/$metadata
Request
completed: OK

GET request: http://servername:60080/#####.odata/APPLICATIONS_RAW?$filter=...

In Visual Studio all I get is...

GET request: http://servername:60080/#####.odata/$metadata


Then it exits naturally. No errors. I feel I'm missing something pretty basic but I just can't find it. If someone has some pointers on this it would be awesome.


Solution

  • I found the solution. And it's not from the oData request itself. It's because this code requires the call TO this code to also be an await. I had been using the following

    await restIngest();
    

    And fixed the issue by changing it to

    restIngest.Wait();