1
made a web api c# where by default returns xml, tried from various internet methods turn this return to json but when I make a request keeps coming in xml, someone could help?
method giving the result:
// GET: api/OINV/5
[ResponseType(typeof(OINV))]
public IHttpActionResult GetOINV(int id)
{
OINV oINV = db.OINV.Find(id);
if (oINV == null)
{
return NotFound();
}
return Ok(oINV);
}
webapiconfig.Cs
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Where is there any return there?
– Leandro Angelo
Put the method that returns the value
– Leandro Vidal
Hello Leandro, thanks for responding, I will be editing and putting the return
– Douglas Souza
Present the method that is returning xml
– Leandro Angelo
@Leandroangelo altered leandro, for a look.
– Douglas Souza
Tried instead of
text/html
forapplication/json
?– Barbetta
already @Barbetta, it even loads in json but in 1 second blink and back to xml, very strange.
– Douglas Souza
[Produces("application/json")]
before the declaration of your controller class no longer resolves?– Leandro Angelo
@Leandroangelo tried here but the error of namespace could not be found
– Douglas Souza
Ok... which version are you talking about and which class your controller is inheriting
– Leandro Angelo
@Leandroangelo web api Entity framework, created the controller with Entity framework, db also
– Douglas Souza
controller with Entity framework? sorry I’ve never heard of it
– Leandro Angelo
This, I right-click on the controller > add>controller folder from which database table to create. It creates crud alone
– Douglas Souza
ok.... but the controller does not inherit from the Entity framework, right? and as for the version, I refer to Asp.net
– Leandro Angelo
Good, I am far from the agr pc but tomorrow I can bring this information
– Douglas Souza
Good morning, @Leandroangelo version 4.6.1
– Douglas Souza