I am using simple.odata.client in my application. The problem is the client is retrieving the whole structure at the first call which is too large (more than 30MB) and so I am getting a timeout? Is there any parameter/setting to prevent the client to retrieve the whole structure. Is there any other package which can help me with my application instead of simple.odata.client
-
Maybe update your question and clarify that you are trying to cache the OData metadata document. Also update what you did as per your comment. – Rohan Jan 15 '20 at 02:17
2 Answers
I use OData Top and Skip in my client request call. For example;
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);
and in my client code, I have a pager that tracks the values I pass to top and skip so I can step through the pages. The Top is the total number of records per page. The annotations object returns a Count property you can use to show the total number of records. I.e.
annotations.Count
Here is a link to the OData.org tutorial that talks about top and skip.
https://github.com/simple-odata-client/Simple.OData.Client/wiki/Results-projection,-paging-and-ordering that talks about paging.

- 927
- 1
- 13
- 41
-
1Thank you for you answer. My problem was that Odata client was fetching the metadata which is more than 30 MB at the first call. I have skipped it by providing to metadata manually. – Yasser Mar 29 '19 at 09:08
-
But if the metadata have changed later, will my problem keep working correctly ? – Yasser Mar 29 '19 at 09:09
The Simple.OData client will retrieve the metadata from the service once for the lifecycle of the object.
You can also initialize the client with a metadata xml string which will prevent the client from making the call.
Below is an except of my code where MetaDataDocumentAsString is the XML metadata as a string. This code also sets the OAuth2 bearer token in the httpclient instance used to create the client.
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);}
See the github issue for more details https://github.com/simple-odata-client/Simple.OData.Client/issues/314

- 578
- 8
- 12