OData WebAPI Parameter Description Option

try using OAP file OAP and invoke parameter action serialized to json without meta information. So, I want to pass an object of type:

public class SomeRequest
{
    public RequestReason Reason { get; set; }
}

public enum RequestReason
{
    New,
    Dublicate
}

      

I created mdel, set up an action:

var action = modelBuilder.Entity<Member>().Action("SomeRequest");
action.Parameter<SomeRequest>("Info");
action.Returns<HttpResponseMessage>();
var model = modelBuilder.GetEdmModel();
configuration.EnableOData(model);

      

Enter the code in the controller:

[HttpPost]
public HttpResponseMessage RequestIDCard(int key, [FromBody]ODataActionParameters param)
{
    object value;
    param.TryGetValue("Info", out value);
///!!!!
}

      

and expect to have a value with real type SomeRequest, distinguish the type and handle it ... Then I make a POST request with headers

Content-Type: application / json; json = light; charset = utf-8 Accept: Usage / JSON; OData = light

and body

{"Info": {"Reason": 1}}

But I am getting an object of type "Newtonsoft.Json.Linq.JObject" and am sure it cannot be distinguished! But if I change the type of the object to int everything works :) Is this a WebAPI OData error or am I doing something wrong?

+3


source to share


1 answer


A couple of wrong things with your use,



  • Enums map to string in aspnet Web API OData. So your requesting authority should have {"Reason": "Duplicate" instead.
  • As Jen already pointed out, application / json; odata = light does not support media type. You can use "application / json; odata = minimalmetadata" or just "application / json".
  • action.Returns <HttpResponseMessage> is not helpful. This would render HttpResponseMessage as a complex type in your service's EDM. I'm not sure how the mapping would look like. Typically, you want to map types which are from your models to the EDM model that you are building. You should choose the more specific type from your models, moreover,

    action.Returns <IDCard> ();

0


source







All Articles