How do I get ServiceStack to work in an MVC4 project?

Storm

I created a new MVC 4 Project, and updated it from NuGet with all required ServiceStack packages.

I added this to my Web.config:

<location path="ss">
  <system.web>
    <!-- httpHandlers added for ServiceStack, this will work for IIS6 and Below -->
    <httpHandlers>
      <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add name="ServiceStack.Factory" path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/>
    </handlers>
  </system.webServer>
</location>

My AppHost:

namespace MySql_Test.App_Start
{
    public class ApplicationHost : AppHostHttpListenerBase
    {
        public ApplicationHost()
            : base("PersonService", typeof(PersonService).Assembly)
        {
        }

        public override void Configure(Funq.Container container)
        {
            SetConfig(new HostConfig { HandlerFactoryPath = "ss" });

            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["DuDealsConnStr"].ConnectionString,
                    ServiceStack.OrmLite.MySql.MySqlDialectProvider.Instance));
        }
    }

    public class PersonService : Service
    {
    }
}

My Global.cs:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        (new ApplicationHost()).Init();

        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
}

When I build and run the project and try to navigate to localhost/ss/metadata it just keeps giving me a 404 page.

Scott

The default MVC4 project uses WebApi by default. You need to prevent WebApi from registering to receive the requests that you want ServiceStack to handle.

See the ServiceStack documentation, Create your first webservice instructions:

Disable WebApi from the default MVC4 VS.NET template
If you are using MVC4 then you need to comment line in global.asax.cs to disable WebApi

//WebApiConfig.Register(GlobalConfiguration.Configuration);

So set your Application_Start to simply be:

protected void Application_Start()
{
    (new ApplicationHost()).Init();
}

If you want ServiceStack to work alongside WebApi then you will need to tell WebApi to not handle requests starting with your ss/ path:

protected void Application_Start()
{
    (new ApplicationHost()).Init();

    AreaRegistration.RegisterAllAreas();

    // Ignore ServiceStack routes
    RouteTable.Routes.IgnoreRoute("ss/{*pathInfo}");

    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Hope that helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I get ServiceStack to work in an MVC4 project?

From Dev

How do I build an ServiceStack.Host.Mvc project?

From Dev

MVC4: How do I get value from partial view for insert/edit

From Dev

MVC4 how do I set a cookie and then redirect to an action

From Dev

MVC4 - How do I pass IPagedList model to controller

From Dev

How can I get host in a Controller using MVC4

From Dev

How do I get ServiceStack binaries for use with the FOSS exception?

From Dev

How do I get the URL of another service in Servicestack

From Dev

How do I get project information while in an mvc controller?

From Dev

How do I get scrapysharp to work in a MVC web app?

From Dev

How do I get a Kendo DatePicker to work inside an MVC Partial?

From Dev

How do I get holder.js to work with bootstrap 4?

From Dev

How do I get dagger 2 to work with Android studio java library project

From Dev

How do I get this project structure in Android Studio (AS) 1.1.0 to work to produce two APKs?

From Dev

How do I get dagger 2 to work with Android studio java library project

From Dev

How to do Attribute Routing in ASP.Net MVC4 and Web API 1 Project?

From Dev

How do I get project root directory?

From Dev

How do I get folders in my Visual Studio solution to appear on my server when I deploy (iis7, asp.net mvc4)?

From Dev

How do I get this recursive rule to work?

From Dev

how do i get the jquery AppendTo to work

From Dev

How do I get this custom font to work?

From Dev

How do I get routes to work with AngularDart?

From Dev

How do I get this case statement to work?

From Dev

How do I get Effort to work with EntityFramework?

From Dev

How do I get pthreads to work in Windows?

From Dev

How do I get my $_Post to work

From Dev

How do i get jQuery to work with me?

From Dev

How do I get this CSS to work in safari

From Dev

How do I get synergy to work?

Related Related

  1. 1

    How do I get ServiceStack to work in an MVC4 project?

  2. 2

    How do I build an ServiceStack.Host.Mvc project?

  3. 3

    MVC4: How do I get value from partial view for insert/edit

  4. 4

    MVC4 how do I set a cookie and then redirect to an action

  5. 5

    MVC4 - How do I pass IPagedList model to controller

  6. 6

    How can I get host in a Controller using MVC4

  7. 7

    How do I get ServiceStack binaries for use with the FOSS exception?

  8. 8

    How do I get the URL of another service in Servicestack

  9. 9

    How do I get project information while in an mvc controller?

  10. 10

    How do I get scrapysharp to work in a MVC web app?

  11. 11

    How do I get a Kendo DatePicker to work inside an MVC Partial?

  12. 12

    How do I get holder.js to work with bootstrap 4?

  13. 13

    How do I get dagger 2 to work with Android studio java library project

  14. 14

    How do I get this project structure in Android Studio (AS) 1.1.0 to work to produce two APKs?

  15. 15

    How do I get dagger 2 to work with Android studio java library project

  16. 16

    How to do Attribute Routing in ASP.Net MVC4 and Web API 1 Project?

  17. 17

    How do I get project root directory?

  18. 18

    How do I get folders in my Visual Studio solution to appear on my server when I deploy (iis7, asp.net mvc4)?

  19. 19

    How do I get this recursive rule to work?

  20. 20

    how do i get the jquery AppendTo to work

  21. 21

    How do I get this custom font to work?

  22. 22

    How do I get routes to work with AngularDart?

  23. 23

    How do I get this case statement to work?

  24. 24

    How do I get Effort to work with EntityFramework?

  25. 25

    How do I get pthreads to work in Windows?

  26. 26

    How do I get my $_Post to work

  27. 27

    How do i get jQuery to work with me?

  28. 28

    How do I get this CSS to work in safari

  29. 29

    How do I get synergy to work?

HotTag

Archive