Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web api interface works locally but not on Azure

My case is very similar to this question, but since he did not get an answer I thought I'd throw some more input.

Everything works fine locally (on the VS embedded server). When I deploy to Azure, I get a 404 error accompanied by "No type was found that matches the controller named...".

However, when I load the routedebugger module the mapping seems ok even on Azure.

What can I do to debug that problem?

Thanks,

Alex

Edit: my routes are created this way:

            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            };
            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "ActionApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Edit 2: Here my controller class

    public class EmployeeController : ApiController
{
    // GET api/<controller>
    public IEnumerable<Employee> Get()
    {
        using (var context = new nws())
        {
            return context.Employees;
        }
    }

    // GET api/<controller>/5
    public Employee Get(int id)
    {
        using (var context = new nws())
        {
            return context.Employees.FirstOrDefault(e => e.ID == id);
        }
    }

    // GET api/<controller>/getbyatid/5
    public Employee GetByAtId(string id)
    {
        using (var context = new nws())
        {
            return context.Employees.FirstOrDefault(e => e.AtUserID == id);
        }
    }

    // POST api/<controller>
    public void Post([FromBody]string value)
    {
    }

    // PUT api/<controller>/5
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/<controller>/5
    public void Delete(int id)
    {
    }

    // GET api/<controller>/timebank/5
    public int? GetTimeBank(string id)
    {
        using (var context = new nws())
        {
            var employee = context.Employees.FirstOrDefault(e => e.AtUserID == id);
            if (employee != null)
                return employee.GetTimeBank();
            return null;
        }
    }
}
like image 719
alexbilo Avatar asked Jan 24 '13 05:01

alexbilo


People also ask

How do I access the premise API from Azure?

Log on to your azure subscription where you have on-premise data gateway registered. Create a resource of type “Logic Apps Custom Connector”. Open a custom connector and click on edit. Choose API Endpoint as SOAP and Call mode as SOAP to REST and then browse to upload WSDL file of your on-premise webservice.

What is Azure Web API?

What is Web API in Azure? Azure Web API Apps, one of the Azure App Service features that offers a rich platform and ecosystem for building, consuming, and distributing APIs in the cloud and on-premises. The key accomplishments using Azure API Apps are as follows: Integrate with SaaS and enterprise applications.


1 Answers

Switch the order of routes and try again.

        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        };
like image 174
Syam Avatar answered Oct 04 '22 20:10

Syam