简体   繁体   English

Simple.odata.client 停止寻找#metadata

[英]Simple.odata.client stops at looking for #metadata

I'm building a client to return data from a V4 oData service.我正在构建一个客户端以从 V4 oData 服务返回数据。 The following code works great in LinqPad v5 and v6.以下代码在 LinqPad v5 和 v6 中运行良好。 But implementing it in Visual Studio ONLY seems to create the GET request for the #metadata, and then ends.但仅在 Visual Studio 中实现它似乎会为#metadata 创建 GET 请求,然后结束。

I'm primarily creating this on Windows 10, but I've also tried it in VS for Mac.我主要在 Windows 10 上创建它,但我也在 VS for Mac 中尝试过。 It runs but also only creates the GET for the #metadata.它运行但也只为#metadata 创建 GET。

I've created new, clean projects.我创建了新的、干净的项目。 I've gone back to using the simplest request examples from the frameworks GIT site.我已经回到使用框架 GIT 站点中最简单的请求示例。 I've tried using new projects using.Net Core (2.2 and 3.0), .Net Standard and.Net Framework.我尝试过使用.Net Core(2.2 和 3.0)、.Net Standard 和.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...在 Visual Studio 中,我得到的只是......

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.如果有人对此有一些指示,那就太棒了。

I found the solution.我找到了解决方案。 And it's not from the oData request itself.它不是来自 oData 请求本身。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM