My service do not work

pnet1pnet1 ✭✭✭✭USMember ✭✭✭✭
edited September 2017 in Xamarin.Forms

I have this class:

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;
        }

And my rest service:

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();
        }
    }

When I put on(on or in?) my URL: http://localhost:9078/api/itens/1000012105 I have this error message:

Were not found HTTP resources that match the URI of the request 'http://localhost:9078/api/itens/1000012105'.

Tagged:

Answers

  • Gigex42Gigex42 ✭✭✭✭ USMember ✭✭✭✭

    I think it is because localhost is wrong here.

    It tries to go to the localhost from you device but not from the server or pc where the webservice is running,

  • pnet1pnet1 ✭✭✭✭ USMember ✭✭✭✭

    @Gigex42, if I call: localhost:9078/api/liberacao work fine. I think that have some problem with my code.

  • pnet1pnet1 ✭✭✭✭ USMember ✭✭✭✭

    I tryed out of localhost by my App, but the error continues. The problem is in my service, the method getItensLiberacao doesn't called. What do must I do?

  • pnet1pnet1 ✭✭✭✭ USMember ✭✭✭✭

    I wish that my service method is broken, but where? I don't know what to do. I installed a WebApiDebugger and now I have other problem with System.Web.Optimization and this DLL is installed and don't have conflict. I changed my service to:

    [AcceptVerbs("Get")]
            public HttpResponseMessage getItensLiberacao(int idorcamento)
            {
                var _itens =  contexto.ItensLibs.Where(it => it.IdOrcamento == idorcamento).FirstOrDefault();
                return Request.CreateResponse(HttpStatusCode.OK, _itens);
    
            }
    

    and yet continues with error. I need to configure a route?

  • JohnHJohnH ✭✭✭✭✭ GBMember ✭✭✭✭✭

    localhost is where ever you are calling it from. So if you call that url from the device, it is looking for localhost on the device, not your PC. Your web service is running on your PC, right? So you need to use the IP address of the PC when calling the url from the device.

  • pnet1pnet1 ✭✭✭✭ USMember ✭✭✭✭
    edited September 2017

    @JohnHair, when I run in my site I have same problem. http://mysite.com.br/autorizador/api/itens/1000023067 and now I have other problem: System.Web.Optimization each day other problem and I cannot solve.

  • JohnHJohnH ✭✭✭✭✭ GBMember ✭✭✭✭✭

    That link throws a 404, I suggest you fix your site before continuing with the app as that will confuse things. Fix 1 bug at a time until the site is working as you expect, then return to the app.

Sign In or Register to comment.