c# – Remove Owin WebApi Return Header

Question:

A simple return query to my REST service brings up the following answer:

{
  "Id": 1,
  "Descricao": "TIROLESA DE AÇO",
  "Und": "UND",
  "Fabrica": "STARROW",
  "Estoque": 9,
  "Preco": 0.39
},

But the query with more than one object starts with {"Result": [

{
"Result":   
[
  {
    ....
    ....
    ....
  } 
],
  "Id": 3,
  "Exception": null,
  "Status": 5,
  "IsCanceled": false,
  "IsCompleted": true,
  "CreationOptions": 0,
  "AsyncState": null,
  "IsFaulted": false
}

This last return brings a "header" ( Result ) that makes it difficult to deserialize my class, would I be able to configure the return so that it only comes with the Array JSON , without this header?

Answer:

I found out that the JSON return with header is related to the signature of the WebApi method that is called, for example:

If it is a sincrono method public List<Produto> GetAllProducts() the return is:

[{
  "Id": 1,
  "Descricao": "TIROLESA DE AÇO",
  "Und": "UND",
  "Fabrica": "STARROW",
  "Estoque": 9,
  "Preco": 0.39
}]

If it is an assincrono method public public Task<List<Produto>> GetAllProductsAsync() the return is:

{
"Result":   
[
  {
    ....
    ....
    ....
  } 
],
  "Id": 3,
  "Exception": null,
  "Status": 5,
  "IsCanceled": false,
  "IsCompleted": true,
  "CreationOptions": 0,
  "AsyncState": null,
  "IsFaulted": false
}
Scroll to Top
AllEscort