1

I have an issues which has just arisen. I have a Web API that has this method:

[HttpGet]
[Route("")]
public IHttpActionResult Get(OrderRequestViewModel model)
{
    var order = new orderHeader()
    {
        sordNo = model.OrderNumber,
        process = orderHeader.orderProcesses.Read
    };

    order.processInfos.read_CoreHistory = model.ReadCoreHistory;

    var response = this.Connection.webServicesAdvanced.ordersHubAction_S(this.SecurityToken, order);

    switch (response.state)
    {
        case processorResult.resultEnum.failed:
        case processorResult.resultEnum.validationfailed:
            throw new HttpException(500, response.info);
        default:
            return Ok(new OrderResponseViewModel(response.obj));
    }
}

The OrderRequestViewModel only has 2 properties: OrderNumber (string) and ReadCoreHistory (boolean).

In my Angular JS application I have a service which looks like this:

.factory('OrderService', ['$http', '$filter', 'apiUrl', function ($http, $filter, api) {
    var _get = function (orderNumber, readCoreHistory) {
        return $http.get(api + 'orders?orderNumber=' + orderNumber + '&readCoreHistory=' + readCoreHistory);
    }

    //-- removed for brevity --//

    var service = {};

    service.get = _get;

    //-- removed for brevity --//

    return service;
}])

When I call the get() method from my controller, if I have fiddler open it states:

No MediaTypeFormatter is available to read an object of type 'OrderRequestViewModel' from content with media type 'application/octet-stream'.

Apparently this is a content type header issue, but I have no access to the ajax call options that I can see. Does anyone know how I can solve this?

1
  • On the comment of @kmcnamee; I would make sure your call is actually hitting the expected end point. Commented Mar 9, 2015 at 18:59

1 Answer 1

1

GET method does not have a body, complex types are filled by data from request body in ASP.NET WebAPI, you should add [FromUri] attribute before your complex type in method signature.

public IHttpActionResult Get([FromUri] OrderRequestViewModel model)
{ ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.