我在我的应用程序中使用了simple.odata.client。问题是客户端在第一次调用时检索整个结构,这太大了(超过30MB),所以我得到了超时?是否有任何参数/设置可防止客户端检索整个结构。除了simple.odata.client,还有没有其他包可以帮助我开发应用程序
发布于 2019-03-28 20:57:13
我在客户端请求调用中使用OData顶部和跳过。例如:
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属性,您可以使用它来显示记录的总数。也就是说。
annotations.Count讨论top和skip的Here is a link to the OData.org tutorial。
发布于 2020-01-15 13:36:05
在对象的生命周期内,Simple.OData客户端将从服务中检索一次元数据。
您还可以使用元数据xml字符串初始化客户端,这将阻止客户端进行调用。
下面是我的代码的一个例外,其中MetaDataDocumentAsString是字符串形式的XML元数据。此代码还在用于创建客户端的OAuth2客户端实例中设置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
https://stackoverflow.com/questions/55034790
复制相似问题