首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止Simple.OData.Client获取整个结构

防止Simple.OData.Client获取整个结构
EN

Stack Overflow用户
提问于 2019-03-07 09:41:10
回答 2查看 942关注 0票数 3

我在我的应用程序中使用了simple.odata.client。问题是客户端在第一次调用时检索整个结构,这太大了(超过30MB),所以我得到了超时?是否有任何参数/设置可防止客户端检索整个结构。除了simple.odata.client,还有没有其他包可以帮助我开发应用程序

EN

回答 2

Stack Overflow用户

发布于 2019-03-28 20:57:13

我在客户端请求调用中使用OData顶部和跳过。例如:

代码语言:javascript
复制
    var accessToken = await _psUtils.GetUspsReferenceApiAccessToken(token);
    var client = new ODataClient(SetODataToken(_psUtils.GetBaseUspsReferenceApiUrl(), accessToken));
    var annotations = new ODataFeedAnnotations();

    addressComplianceCodes = await client.For<AddressComplianceCode>()
        .Filter(x => x.Description.Contains(searchValue) || x.Code.Contains(searchValue))
        .Top(pageSize).Skip(skip)
        .OrderByDescending(sortColumn)
        .FindEntriesAsync(annotations, token);

在我的客户机代码中,我有一个分页程序,它跟踪我传递给top和跳过的值,这样我就可以逐个浏览页面。Top是每页的记录总数。annotations对象返回一个Count属性,您可以使用它来显示记录的总数。也就是说。

代码语言:javascript
复制
annotations.Count

讨论top和skip的Here is a link to the OData.org tutorial

讨论分页的https://github.com/simple-odata-client/Simple.OData.Client/wiki/Results-projection,-paging-and-ordering

票数 1
EN

Stack Overflow用户

发布于 2020-01-15 13:36:05

在对象的生命周期内,Simple.OData客户端将从服务中检索一次元数据。

您还可以使用元数据xml字符串初始化客户端,这将阻止客户端进行调用。

下面是我的代码的一个例外,其中MetaDataDocumentAsString是字符串形式的XML元数据。此代码还在用于创建客户端的OAuth2客户端实例中设置OAuth2承载令牌。

代码语言:javascript
复制
           HttpClient.BaseAddress = new Uri(AppSettings.Dynamics365.WebAPI_ServiceRootURL);

           //Use the httpClient we setup with the Bearer token header           
           ODataClientSettings odataSettings = new ODataClientSettings(HttpClient, new Uri(WebAPI_VersionRelativeURL, UriKind.Relative))
           {
               //Setting the MetadataDocument property prevent Simple.OData from making the expensive call to get the metadata
               MetadataDocument = MetaDataDocumentAsString
           };
           _ODataClient = new ODataClient(odataSettings);
           HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GetToken().Access_token);}

有关更多详细信息,请参阅github问题https://github.com/simple-odata-client/Simple.OData.Client/issues/314

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55034790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档