left-icon

ServiceStack Succinctly®
by Zoran Maksimovic

Previous
Chapter

of
A
A
A

CHAPTER 4

Solution Configuration

Solution Configuration


It’s finally time to start coding. In this chapter, we will see how to create the ServiceStack.Succinctly.Host project and enable the ServiceStack framework.

The first thing to do is to create a new solution and create a list of projects as specified in the following table.

  1. Project list

Visual Studio Project Name

Visual Studio Project Type

ServiceStack.Succinctly.Host

ASP.NET Empty Web Application

ServiceStack.Succinctly.ServiceInterface

Windows Class Library

OrderManagement.Core

Windows Class Library

OrderManagement.DataAccessLayer

Windows Class Library

Step 1: Create a New ASP.NET Empty Web Application

Use Visual Studio to create a new ASP.NET Empty Web Application project and call it ServiceStack.Succinctly.Host.

Creation of a new ASP.NET Empty Web Application project

  1. Creation of a new ASP.NET Empty Web Application project

Step 2: Install ServiceStack Binaries and Configure web.config

In order to run our first web service, we need to add ServiceStack as a project reference. This can be done manually or by using NuGet, which is the easiest way in my opinion.

By running the following command in Visual Studio’s Package Manager Console, the reference will be automatically added to the project:

PM> Install-Package ServiceStack

The following packages will be installed by default:

  • ServiceStack
  • ServiceStack.Common
  • ServiceStack.Interfaces
  • ServiceStack.OrmLite
  • ServiceStack.OrmLite.SqlServer
  • ServiceStack.Redis
  • ServiceStack.ServiceInterface
  • ServiceStack.Text

Tip: If you want to mix ServiceStack with your existing ASP.NET or ASP.NET MVC applications, there are two packages that were created specifically to help you install ServiceStack automatically:

PM> Install-Package ServiceStack.Host.Mvc
PM> Install-Package ServiceStack.Host.AspNet

After adding the required binary files to the project, we need to instruct our application to use the ServiceStack HTTP handler, which will act as an entry point of the application. This is done by putting the following configuration in the web.config file.

<configuration>

  <!-- Required for IIS 6.0 (and above) -->

  <system.web>

    <httpHandlers>

     <add path="*"

          type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, 

ServiceStack"

          verb="*"/>

    </httpHandlers>

    <compilation debug="true"/>

  </system.web>

  <!-- Required for IIS 7.0 -->

  <system.webServer>

    <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>

</configuration>

Step 3: Creating the Application Host

In order to run a ServiceStack web service, we have to start the application host when the IIS application starts. There can be only one application host per application pool and, therefore, creating multiple application hosts is not allowed. The following code represents the minimum AppHostBase implementation. The Global class refers to the Global.asax.cs file.

public class Global : HttpApplication

{

    public class ServiceAppHost : AppHostBase

    {

        public ServiceAppHost()

            : base("Order Management", typeof(ServiceAppHost).Assembly)

        {

        }

        public override void Configure(Container container)

        {

        }

    }

    protected void Application_Start(object sender, EventArgs e)

    {

        new ServiceAppHost().Init();

    }

}


Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.