0
This message I get in the browser or Postman
"Message": "No HTTP resources matching URI of request 'http://localhost:9078/api/items/1000012105'.", "Messagedetail": "No action found in 'Items' controller that matches the request."
The problem is that I am building a service where I pass an ID to the url so that only the items from that budget come in. In the controller it looks like this:
public class ItensController : ApiController
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLiberacao itens = new ItensLiberacao();
[AcceptVerbs("Get")]
public IEnumerable<ItensLibDTO> getItensLiberacao(int idorcamento)
{
return itens.getItensLib(idorcamento).AsEnumerable().ToList();
}
}
And here the class Itensliberacao:
public class ItensLiberacao
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLibDTO libDTO = new ItensLibDTO();
public List<ItensLibDTO> getItensLib(int idorcamento)
{
var lista = contexto.ItensLibs
.Where(itens => itens.IdOrcamento == idorcamento)
.Select(item => new ItensLibDTO
{
Produto = item.Produto,
Qtde = item.Qtde.ToString(),
Unitario = item.Unitario.ToString(),
Custo = item.Custo.ToString(),
CustoDiario = item.CustoDiario.ToString(),
UltCondicao = item.UltCondicao.ToString(),
Total = item.Total.ToString()
}).ToList();
return lista;
}
}
How do I fix this? What else is missing for the service to work? The number: 1000012105 is the id of an existing budget in the database.
EDIT1
I changed my service to that, and it’s still the same mistake:
[AcceptVerbs("Get")]
public HttpResponseMessage getItensLiberacao(int idorcamento)
{
var _itens = contexto.ItensLibs.Where(it => it.IdOrcamento == idorcamento).FirstOrDefault();
return Request.CreateResponse(HttpStatusCode.OK, _itens);
}
EDIT2
If I change the method and the service works, so:
public class ItensLiberacao
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLibDTO libDTO = new ItensLibDTO();
public List<ItensLibDTO> getItensLib()
{
var lista = contexto.ItensLibs
//.Where(itens => itens.IdOrcamento == idorcamento)
.Select(item => new ItensLibDTO
{
Produto = item.Produto,
Qtde = item.Qtde.ToString(),
Unitario = item.Unitario.ToString(),
Custo = item.Custo.ToString(),
CustoDiario = item.CustoDiario.ToString(),
UltCondicao = item.UltCondicao.ToString(),
Total = item.Total.ToString()
}).ToList();
return lista;
}
}
And the service:
public class ItensController : ApiController
{
AutorizadorContext contexto = new AutorizadorContext();
ItensLiberacao itens = new ItensLiberacao();
[AcceptVerbs("Get")]
public IEnumerable<ItensLibDTO> getItensLiberacao()
{
return itens.getItensLib().AsEnumerable().ToList();
}
}
Your route is the default web api?
– Gabriel Coletta
Test: http://localhost:9078/api/items/getitensrelease/1000012105 and make sure it’s a request is a GET
– Gabriel Coletta
@Gabrielcoletta, still the same problem. The same error message
– pnet
Guys, what I noticed is that it doesn’t enter the method when I call the url. I use the default route, as my colleague @Gabrielcoletta asked. I changed the method and still it doesn’t work. I am since 4:30 am trying, reading and nothing yet, so far.
– pnet
I don’t know if it can be that, but when I change the method and the service to receive by ID, I’m bringing a list and it should be, I think,
FirstOrDefault()
. I think that might be it, and I’m going to test it.– pnet
What version of the webapi you are using?
– Grupo CDS Informática
@Grupocdsinformática, how I see it?
– pnet
@pnet Checks the version of the webapi package in nuget. I asked why there is a way to do it, including the following attribute in the controller method: [Route( "itensrelease/{marking}" )] and passing this value as attribute to the controller [Routeprefix("api/items")]
– Grupo CDS Informática
@Grupocdsinformática, picking up by the installed packages I have the following: Microsoft.AspNet.Webapi Version 5.2.3, I don’t know if that’s it, I think so.
– pnet
The problem is that it doesn’t even enter the method in the controller(service) and I can’t debug it. It’s totally wrong and I don’t know what it is and I have no idea
– pnet
Sets the icon parameter to id and test only.
– Thiago Silva
@pnet is Webapi 2.2, tests with what I’ve been through, able to solve.
– Grupo CDS Informática
@Thiagosilva, this way entered the method. Gave another error in the double field, but this is for another post. Thanks. Post as an answer that I mark.
– pnet
@Grupocdsinformática, I switched from branding to id and it worked. I was without internet, so I didn’t comment before. And how I see the webapi version?
– pnet
@pnet, I saw by the version of Assembly that passed me above, I only researched from there ;)
– Grupo CDS Informática