Skip to content

Run servicestack side by side with another web framework

ChuckSavage edited this page Jul 20, 2012 · 6 revisions

In order to avoid conflicts with your existing ASP.NET web framework it is recommended to host your ServiceStack web services at a custom path. This will allow you to use ServiceStack together with an existing web framework e.g. ASP.NET MVC 3 or FUBU MVC, etc.

The location configuration (to your root Web.config file) below hosts your webservices at custom path: /api

<location path="api">
  <system.web>
    <httpHandlers>
      <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
    </httpHandlers>
  </system.web>

  <!-- Required for IIS 7.0 -->
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>
</location>

<!-- Required for MONO -->
<system.web>
  <httpHandlers>
    <add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
  </httpHandlers>
</system.web>
<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
</system.webServer>

Note: Due to limitations in IIS 6 - the /custompath must end with .ashx, e.g: path="servicestack.ashx"

You also need to configure the root path in your AppHost.

public override void Configure(Container container)
{
    SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" });
}

To avoid conflicts with ASP.NET MVC add an ignore rule in Global.asax RegisterRoutes method e.g: routes.IgnoreRoute ("api/{*pathInfo}");

See also:

Clone this wiki locally