So I have a web api which returns a byte array like this
public byte Validate()
byte buffer = licensePackage.ToByteArray();
With the given information I think it must have something to do with content negotiation. I can't tell about the reason, but what I'm sure it's that there is a different approach to serve files behind a Web Api.
var response = Request.CreateResponse(HttpStatusCode.OK); var stream = new FileStream(pathToFile, FileMode.Open, FileAccess.Read); response.Content = new StreamContent(stream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return ResponseMessage(response);
With this solution, you serve the file contents returning an
IHttpActionResult instance. And, returning a response with
StreamContent you are conceptually returning an array of bytes that must not be modified by Web Api. Content negotiation is not going to alter anything.