I have an existing MVC 4 application. I wanted to add Service Stack to it. I tried installing the MVC host nuget package:
Install-Package ServiceStack.Host.Mvc
It installed 2 files in App_Start. I noticed I had to make a slight change because I was getting a build error:
In App_State/WebServiceExamples.cs, I had to update the interface references:
From: public class HelloService : Service
To: public class HelloService : ServiceStack.ServiceInterface.Service
I then went ahead and double checked the Web.config settings:
<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>
I then ran the application and went to /api, I got a 404. From some further research I decided to manually update the endpoint via the apphost file:
SetConfig(new EndpointHostConfig
{
ServiceStackHandlerFactoryPath = "api",
});
This also didn't seem to work. What else am I missing?
Thanks for your time.
This should be in your web.config file as well:
<httpHandlers>
<add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
Also don't forget to remove the MVC '/api' route/path. You need to remove it so that ServiceStack and MVC don't compete for the '/api' route/path.
//REMOVE THIS FROM RouteConfig
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
);
If you want to be real explicit you can also add this to the RouteConfig
routes.IgnoreRoute ("api/{*pathInfo}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With