I've written my first ASP.NET Core Web API server. The routing is working and it is sending/receiving. I'd like to send a raw Byte array in response to a Get and I'd like to bypass any serialization (as well as any deserialization in my WPF client). For example, in my server:
[HttpGet("api/data")]
public Byte[] GetData()
{
Byte[] data = new Byte[]{1, 2, 3, 4, 5};
return data; // No JSON, BSON or anything else...just my array. Is it done this way?
}
In my WPF client I'd like to use the HttpClient class to receive the array - no deserialization required:
// Assume an instantiated and initialized HttpClient object called "httpCLient"
HttpResponseMessage response = httpClient.GetAsync("/api/data").Result;
// Now what?
I've scoured the internet but I haven't found an example of this, and I've been unable to figure out on my own. Could somebody please show me how this is done?
Update: I believe the client-side Byte[]
retrieval can be accomplished via "HttpContent.ReadAsByteArrayAsync()" as shown here: Convert HttpContent into byte[]. I still am unsure as to how to send the raw (unserialized) Byte[]
from the ASP.NET Core Web API side however.