You can install ServiceStack in 3 ways:
You can find info about these here: https://github.com/ServiceStack/ServiceStackVS.
For complete guide go here: https://github.com/ServiceStack/ServiceStack/wiki/Self-hosting
To setup:
Install-Package ServiceStack
AppHost
to thigh everything together: //This your main entry point of the application
public class AppHost : AppSelfHostBase {
public AppHost()
: base("HttpListener Self-Host", typeof(HelloService).Assembly) {}
public override void Configure(Funq.Container container) { }
}
//Run it!
static void Main(string[] args)
{
var listeningOn = args.Length == 0 ? "http://*:1337/" : args[0];
var appHost = new AppHost()
.Init()
.Start(listeningOn);
Console.WriteLine("AppHost Created at {0}, listening on {1}",
DateTime.Now, listeningOn);
Console.ReadKey();
}
Now you can start developing your api Services.
For complete Mvc integration guide: https://github.com/ServiceStack/ServiceStack/wiki/Mvc-integration
First download your nuget packages: Install-Package ServiceStack.Mvc
Setup your ServiceStack Apphost
public class AppHost : AppHostBase
{
public AppHost() : base("MVC 4", typeof(MyServices).Assembly) {}
public override void Configure(Container container)
{
SetConfig(new HostConfig {
HandlerFactoryPath = "api"
});
ControllerBuilder.Current.SetControllerFactory(
new FunqControllerFactory(container));
}
}
//Bootstrap your appHost through MVC Global.asax:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
new AppHost().Init();
}
}
Now to run ServiceStack services, we can add web.Config to make ServicStack run under a certain path, eg: /api/*
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack"
verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory"
type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"
preCondition="integratedMode"
resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>