Raghu
Raghu

Reputation: 3091

Why does not MapHttpAttributeRoutes work in Stateless Web API in service fabric?

By default, VS 2015 templates for Web API in Service Fabric create a OWIN based hosting for Web API controllers. The default code in Startup.cs file for this service is:

public static void ConfigureApp(IAppBuilder appBuilder)
{
    // Configure Web API for self-host. 
    HttpConfiguration config = new HttpConfiguration();

    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

    appBuilder.UseWebApi(config);
}

I replaced this code with following:

public static void ConfigureApp(IAppBuilder appBuilder)
{
    // Configure Web API for self-host. 
    HttpConfiguration config = new HttpConfiguration();

    config.MapHttpAttributeRoutes();

    appBuilder.UseWebApi(config);
}

and added

[RoutePrefix("mycontroller")]
public class ValuesController : ApiController
{
    ...
}

and try to navigate it by http://localhost:port/mycontroller.

It does not work.

The same code works fine when I create a web api controller with ASP.NET host project.

Am I doing something wrong here?

Upvotes: 2

Views: 1402

Answers (1)

Vaclav Turecek
Vaclav Turecek

Reputation: 9050

Attribute routing works just fine, it's the same ASP.NET whether it's hosted on Service Fabric or somewhere else. We use attribute routing in our Party Cluster sample. As Federico commented, make sure you have more than just the RoutePrefix on your controllers.

Upvotes: 0

Related Questions