How can I transfer data via odata?
I currently have a route that returns archived date data stored in protobuf files. I am currently using PushStreamContent
to write the result to json. Here's what I'm doing now:
[HttpGet,Route(...)]
public async Task<HttpResponseMessage>(
string asset,
DateTime archiveDate,
CancellationToken token
){
var archivedData = await _archiveService.GetArchivedData(asset,archiveDate,token);
if(archivedData == null){
return await NotFound().ExecuteAsync(token).ConfigureAwait(false);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
var res = ConvertToWire(asset,archivedData);
var typeFormatter = Configuration.Formatters.First();
response.Content = new PushStreamContent(async (stream, content, transport) =>
{
using (var outerStream = new BufferedStream(stream, 8*1024))
{
await typeFormatter.WriteToStreamAsync(res.GetType(), res, outerStream,
content, transport, token).ConfigureAwait(false);
}
stream.Close();
}, JsonUtf8);
return response;
};
ConvertToWire is mostly aware of the assets we support and applies the wire format and returns it as IEnumerable<T>
. I can make this return IQueryable<T>
quite easy ( res.ToQueryable()
). With this approach, I can easily output data from files. How can I add Odata support while still being able to stream the result set. Some of the assets have very large files (50+ MB) so streaming is required.
source to share
No one has answered this question yet
Check out similar questions: