ServiceStack and MVC4 do not connect

I have an existing MVC 4 application. I wanted to add a Service Stack to it. I tried installing the nuget package of the MVC host:

Install-Package ServiceStack.Host.Mvc

App_Start has 2 files installed. I noticed that I had to make a small change because I was getting a build error:

In App_State / WebServiceExamples.cs, I had to update the links to the interface:

From: public class HelloService : Service

To: public class HelloService : ServiceStack.ServiceInterface.Service

Then I went ahead and double-checked the settings of Web.config:

<location path="api">
  <system.web>
    <httpHandlers>
      <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
    </httpHandlers>
    <authorization>
      <allow users="*"/>
    </authorization>
  </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>

Then I launched the application and switched to / api, I got 404. From some further research, I decided to manually update the endpoint via the apphost file:

SetConfig(new EndpointHostConfig
{
ServiceStackHandlerFactoryPath = "api",
});

That didn't work either. What else am I missing?

Thank you for your time.

+5
source share
1 answer

web.config:

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

/ MVC '/api'. , ServiceStack MVC //api.

//REMOVE THIS FROM RouteConfig
routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
);

, RouteConfig

routes.IgnoreRoute ("api/{*pathInfo}");
+6

All Articles