15

I am just trying to get Service Stack running under a mvc4 project. Does the ServiceStack.Host.Mvc nuget package work with mvc 4.0 ? I installed it and added the routes.IgnoreRoute("api/{*pathInfo}"); to the routing config but it does not find the route when I go to

/api/metadata

and I get the error:

No HTTP resource was found that matches the request URI 'http://localhost:51681/api/metadata'.

Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113
user1661621
  • 797
  • 9
  • 15
  • I am also getting same issue. In chrome console it is showing that because of security issue it is not allowing to load javascript. I don't know why? – kunjee Oct 09 '12 at 01:03
  • please accept answer if your issue is solved, if issue is still there please let us know details. – kunjee Dec 12 '12 at 04:42

3 Answers3

15

Found the solution. Whenever we are creating new asp.net mvc4 project it comes with Asp.Net Web Api. And that also having path api/. I don't you need both together, so just removed that modules using nuget package manager and it will work like anything.

If you still stuck anywhere let me know. As it is working now for me with asp.net mvc4.

kunjee
  • 2,739
  • 1
  • 23
  • 38
  • 6
    Commenting this line: "WebApiConfig.Register(GlobalConfiguration.Configuration);" from the Global.asax.cs should do the trick as well. – Ameer Deen Dec 22 '12 at 10:52
  • 1
    I just wasted like 3 hours on this crap. Someone should update the servicestack docs. – tom.dietrich Mar 26 '13 at 18:56
  • 1
    @tom.dietrich please see my answer below. Instructions are in the Readme.txt in the ServiceStack.Host.Mvc NuGet package. Anyone can update ServiceStack's wiki, you can add a comment on the aspnetwebstack project site to make this easier, thx. – mythz Mar 27 '13 at 04:12
  • @mythz I've gone ahead and added that info to the wiki page https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework . Thanks for the awesome support. – tom.dietrich Mar 27 '13 at 14:09
10

In the README.txt page when you install the ServiceStack.Host.Mvc NuGet package shows the instructions needed for installing ServiceStack with MVC, we've added an extra line for support with MVC4 since it comes bundled with a conflicting WepApi.

For MVC4 applications you also need to unregister WebApi, by commenting out this line:

    //WebApiConfig.Register(GlobalConfiguration.Configuration);

We also dislike having to provide manual install instructions to disable WebApi from the default install of MVC4 but unfortunately this is the best we can do at the moment with what's available.

The ServiceStack docs is a community wiki

If you feel there is something missing from ServiceStack's wiki docs, please feel free to add them, as they are a community wiki docs maintained by and are for the ServiceStack community.

Asking the aspnetwebstack team for an easier way to disable WebApi

We've already requested from the aspnetwebstack team if they could provide an easier and automated way to be able to disable WebApi via Nuget, feel free to show your support of this feature by commenting on the feature request.

Full README.txt instructions

To make the README more searchable I will repeat them here:


Hosting in ASP.NET MVC is very similar to hosting in any ASP.NET framework, i.e. The ServiceStack AppHost still needs to be initialized on start up in your Global.asax.cs (or WebActivator), e.g:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        new AppHost().Init();
    }
}

You MUST register ServiceStacks '/api' path by adding the lines below to MvcApplication.RegisterRoutes(RouteCollection) in the Global.asax:

routes.IgnoreRoute("api/{*pathInfo}"); 
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); //Prevent exceptions for favicon

Place them before the current entries the method.

For MVC4 applications you also need to unregister WebApi, by commenting out this line:

    //WebApiConfig.Register(GlobalConfiguration.Configuration);

To enable the Mini Profiler add the following lines in to MvcApplication in Global.asax.cs:

protected void Application_BeginRequest(object src, EventArgs e)
{
    if (Request.IsLocal)
        ServiceStack.MiniProfiler.Profiler.Start();
}

protected void Application_EndRequest(object src, EventArgs e)
{
    ServiceStack.MiniProfiler.Profiler.Stop();
}

For more info on the MiniProfiler see v3.09 of the https://github.com/ServiceStack/ServiceStack/wiki/Release-Notes

The Urls for metadata page and included Services:

mythz
  • 141,670
  • 29
  • 246
  • 390
  • I've seen on some nuget packages the readme.txt popping up after installation. It might be beneficial to have this happen with the mvc package. I wasn't even aware of the readme.txt, I was following along on the side-by-side instructions on the wiki. – tom.dietrich Mar 28 '13 at 11:33
1

I new for use service stack , I use MVC 4 Application too, the answer @mythz is right. but for

routes.IgnoreRoute("api/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); //Prevent exceptions for favicon

place in AppStart/RouteConfig.cs

My application running well :D

masadi zainul
  • 397
  • 4
  • 14