# Using Standard Visual Studio Web API Template

## Content

Complete the following steps to configure FlexReport Web API using standard Visual Studio Template for Web API:

* [Step 1: Configure Web API Project](/componentone/docs/webapi/online-webapi/Services/ReportServices/WorkingwithReports/UsingStandardVSWebAPITemplate#step-1-configure-web-api-project)
* [Step 2: Add Report files to the Project](/componentone/docs/webapi/online-webapi/Services/ReportServices/WorkingwithReports/UsingStandardVSWebAPITemplate#step-2-add-report-files-to-the-project)
* [Step 3: Set Report's Root Location and Use C1 Web APIs](/componentone/docs/webapi/online-webapi/Services/ReportServices/WorkingwithReports/UsingStandardVSWebAPITemplate#step-3-set-reports-root-location-and-use-c1-web-apis)
* [Step 4: Deploy FlexReport Web API Service](/componentone/docs/webapi/online-webapi/Services/ReportServices/WorkingwithReports/UsingStandardVSWebAPITemplate#step-4-deploy-report-web-api-service)

### Step 1: Configure Web API Project

Complete the following steps to configure Web API project:

1. Create a new ASP.NET Web API Project.
2. Add the FlexReport Web API package from NuGet.
<br>
    If you have installed MVC Edition, the NuGet source path gets already set inside Visual Studio.
<br>
    ![](https://cdn.mescius.io/document-site-files/images/66c72527-2495-47b0-9257-2ee31dae74e5/images/addpkgsrc.png)
<br>
    Alternatively, you can manually add the source path from **NuGet Package Manager** \| **Package Sources** option available in **Options** dialog box, which appears on selecting **Tool** \| **NuGet Package Manager** \| **Package Manager Settings**.
    In the NuGet package manager the Report Service is listed as shown in the following image:
<br>
    ![](https://cdn.mescius.io/document-site-files/images/66c72527-2495-47b0-9257-2ee31dae74e5/images/reportserviceswebapi.png)
<br>
    FlexReport Web API adds the following references to the project:
<br>
    ![](https://cdn.mescius.io/document-site-files/images/66c72527-2495-47b0-9257-2ee31dae74e5/images/reportwebapiref.png)
3. License your Web API application. Create a **licenses.licx** file within Properties folder of your application and add the following code in it:

    ```LICENSES.LICX
    C1.Web.Api.LicenseDetector, C1.Web.Api
    C1.Web.Api.Report.LicenseDetector, C1.Web.Api.Report
    ```


### Step 2: Add Report files to the Project

1. Create a folder named **Files** in your application.
2. Add the FlexReport Definition file to it.
<br>
    If the report is using any local database (such as MDB or MDF files), then add the database file to the **App\_Data** folder of your project. However, make sure that the connection string of the reports are pointing to the App\_Data folder accordingly.
<br>
    ![](https://cdn.mescius.io/document-site-files/images/66c72527-2495-47b0-9257-2ee31dae74e5/images/flexreportdatasource.png)

### Step 3: Set Report's Root Location and Use C1 Web APIs

1. Open the **Startup.cs** file and add the following code to Configuration method:

    ```csharp
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);
        var folder = GetFullRoot("Files");
        app.AddDiskStorage("root", folder);
        ConfigureAuth(app);
    }
    ```

> **Note:** Make sure you add **Microsoft.Owin.Cors** Nuget package in your application, for app.UseCors();

2. Add the following GetFullRoot function in the startup class.

    ```csharp
    private static string GetFullRoot(string root) {
    var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
    var fullRoot = Path.GetFullPath(Path.Combine(applicationBase, root));
    if (!fullRoot.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) {
        fullRoot += Path.DirectorySeparatorChar;
      }
      return fullRoot;
    }
    ```
3. Open Web.Config and add the following entry under handlers inside system.webServer Node.

    ```xml
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="api/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    ```
4. In the Web.config file, ensure that the **WebDAVModule** and the **WebDAV** handler are removed from \<system.webServer> as shown below:

    ```xml
    <system.webServer>
    <modules>
          <remove name="WebDAVModule" />
        </modules>
    <handlers>
          <remove name="WebDAV" />
          .........
        </handlers>
    </system.webServer>
    ```

### Step 4: Deploy Report Web API Service

1. Compile the project.
2. Deploy the project to IIS.

The Web API URL, for service will be hosted on local IIS.

>type=note
> **Note**: Once you have successfully created **Web API URL** for Report Services, you can access and view reports stored in the service using FlexViewer for MVC and Wijmo Viewer. For more information on how to view reports, see [Viewing Reports in FlexViewer](http://helpcentral.componentone.com/nethelp/c1mvchelpers/webframe.html#ViewingReportsinFlexViewer.html).