Consume WebAPI by AngularJs

1

I have a POST method in the WebAPI, and this is the Api RoutePrefix, 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 it looks like this: link

Domain: http://grupo.ddns.net

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

RoutePrefix (API): api/v1/crm/

Route (POST method): registros

The problem is:

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

Given this structure of the directory server, and the API Routes, how should I mount the URI to work on the net? Or, should I do something different to work better?

Remembering that the server is in the company and as seen in the domain above, it has no fixed IP.

    
asked by anonymous 13.07.2016 / 15:34

1 answer

0

In theory, without access to the other Api Web configurations, everything is fine.

You have access to the Web server where the application was published to see if the request actually reached it (there may be a problem with proxy, dns, etc., so that the request is not actually arriving at your application) ?

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

    
15.11.2016 / 21:05