Consuming Webapi by Angularjs

Asked

Viewed 404 times

1

I have a POST method in Webapi, and this defined the Routeprefix of the Api, the Route of the POST method and Cors is enabled.

[RoutePrefix("api/v1/crm")]
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class EmpresaParticipanteController : ApiController
{
    private SigCodeFirst db = new SigCodeFirst();

    [HttpPost]
    [Route("registros")]
    public HttpResponseMessage PostRegistro(EmpresaParticipante empresaParticipante)
    {
        if (empresaParticipante == null)
            return Request.CreateResponse(HttpStatusCode.BadRequest);

        try
        {
            db.EmpresaParticipante.Add(empresaParticipante);
            db.SaveChanges();

            var resultado = empresaParticipante;
            return Request.CreateResponse(HttpStatusCode.Created, resultado);
        }
        catch (System.Exception)
        {
            return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao incluir registro.");
        }
    }
}

In Angularjs, the script is as follows:

var crmApp = angular.module("Crm", []);
crmApp.controller("CrmCtrl", function ($scope, $http) {

   $scope.adicionarRegistro = function (empresaParticipante) {
       $http.post("http://grupo.ddns.net/GRUPO/api/v1/crm/registros", empresaParticipante).success(function (data) {
           delete $scope.empresaParticipante;
           $scope.novoCrmForm.$setPristine();
           console.log(empresaParticipante);
           carregarRegistros();
       });
   };
});

in the URI this way: http://grupo.ddns.net/GRUPO/api/v1/crm/registros

Dominio: http://grupo.ddns.net

Directory inside the server (where code is published): GRUPO/

Routeprefix (from the API): api/v1/crm/

Route (POST method): registros

The problem is this:

when I put this application on the net, it shows a path error not found (404) in this URI above.

In view of this server structure with directory, and the API Routes, how should I set up the URI to work the registration on the net? Or, I must do something different to work better?

Remembering that the Server stays in the company and as seen in the domain above, has no fixed IP.

2 answers

1

Bruno, good morning. So, in the test of ports I use often shows that there is no port 80 (http) open in your IP.

Use this site to check, you need to go through this procedure or it will not work. If you have a public IP that is dynamic, most likely you will only need to open the port on(s) router(s) to your machine’s IP.

Site for testing doors: https://www.yougetsignal.com/tools/open-ports/ Put your public IP and port 80. As long as it’s not positive no one will access.

0

In theory, without having access to the other Web Api settings, it’s all right.

You have access to the ones on the web server where the application was published to check if the request actually got to it (there may be some problem with proxy, dns, etc, so that the request is not really coming in your application)?

If you confirmed in the server log that the request registered error 404, you can try to activate the Failed Request Tracing from IIS to find out the reason for the IIS pipeline error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.