Comprendo che l'API WEB utilizza la negoziazione del contenuto per Accept - Content-Type per restituire json o xml. Questo non è abbastanza buono e ho bisogno di essere in grado di decidere pragmaticamente se voglio restituire json o xml.Come restituire JSON da MVC WEB API Controller
Internet è invaso da esempi di utilizzo obsoleti HttpResponseMessage<T>
, che non è più presente in MVC 4.
tokenResponse response = new tokenResponse();
response.something = "gfhgfh";
if(json)
{
return Request.CreateResponse(HttpStatusCode.OK, response, "application/json");
}
else
{
return Request.CreateResponse(HttpStatusCode.OK, response, "application/xml");
}
Come faccio a cambiare il codice di cui sopra in modo che funzioni?
Giusto! Il mio errore è stato che il metodo Get() aveva un tipo di ritorno di tokenResponse. Grazie! – user1662812