I'm trying to expose a document stream as an Action Method on a specific type. It would look something like this:
/odata/MyType(123)/stream <-- this returns a binary stream of data.
When accessing the above endpoint using GET I only get a 404, even though the endpoint is exposed as [HttpGet] on the Controller.
Sematically it would make sense to access this resource using the Get verb, as this is simply an operation for retrieval of data, and not side-effecting.
So far I've only gotten this to work by exposing the action method under the POST-verb.
The action method controller implementation currently look like this:
[HttpPost] // <-- I want this to be [HttpGet]
public HttpResponseMessage Test([FromODataUri] int key, ODataActionParameters parameters)
{
var fileStream = File.OpenRead(@"c:\somefile");
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(fileStream)
};
}
The code for registering the action method on 'MyType'
var entityTypeConfiguration = mapper.Builder.Entity<MyType>();
var actionConfiguration = entityTypeConfiguration.Action("stream");
actionConfiguration.Returns<HttpResponseMessage>();
The implementation is inspired by this article: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-actions
Anyone know how I can possible expose this action method as a Get?
Question is old, but I have been struggling with this and the solution I found in my case may be useful for others: define the "Action" GET as a "Function" instead of an "Action".
In the scenario presented in the question, this would be:
var actionConfiguration = entityTypeConfiguration.Function("stream");
This is recommended in the documentation: "The difference between actions and functions is that actions can have side effects, and functions do not. Both actions and functions can return data."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With