3

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

4

2 回答 2

1

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

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

下面是我的代码的一个例外,其中 MetaDataDocumentAsString 是作为字符串的 XML 元数据。此代码还在用于创建客户端的 httpclient 实例中设置 OAuth2 持有者令牌。

           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

于 2020-01-15T05:36:05.120 回答
1

我在客户端请求调用中使用 OData Top 和 Skip。例如;

    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 是每页的记录总数。annotations 对象返回一个 Count 属性,您可以使用它来显示记录的总数。IE

annotations.Count

这是 OData.org 教程的链接,该教程讨论了 top 和 skip。

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

于 2019-03-28T12:57:13.167 回答