[英]Prevent Simple.OData.Client from fetching the whole structure
我在我的應用程序中使用 simple.odata.client。 問題是客戶端在第一次調用時檢索整個結構太大(超過 30MB),所以我超時了? 是否有任何參數/設置可以防止客戶端檢索整個結構。 有沒有其他包可以幫助我完成我的應用程序而不是 simple.odata.client
我在客戶端請求調用中使用 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。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.