Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Integrate the Web API into an Existing XAF Blazor Application

  • 3 minutes to read

This topic describes how to add the Web API service to a Blazor Server project.

#Add Web API Service: Core Functionality

#Install NuGet Packages

Install the following NuGet packages to the Blazor Server project (MySolution.Blazor.Server):

  • DevExpress.ExpressApp.WebApi
  • Swashbuckle.AspNetCore
  • DevExpress.ExpressApp.WebApi.Xpo - XPO applications only

See the following topic for more information on how to install DevExpress NuGet packages: Choose Between Offline and Online DevExpress NuGet Feeds.

#Add Service Configuration Code

Use the code below to configure services for the Web API:

File: MySolution.Blazor.Server\Startup.cs

using DevExpress.ExpressApp.WebApi.Services;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.OData;
// ...
public void ConfigureServices(IServiceCollection services) {
// ...     
    services.AddXafWebApi(Configuration, options => { 
        // To make a Business Object available via Web API and
        // to generate GET, POST, PUT, and DELETE HTTP methods for it,
        // uncomment the following line.
        // !!!
        // options.BusinessObject<YourBusinessObject>();
        // !!!
    })
    // In EF Core applications, do nothing. 
    // In XPO applications, uncomment the following line.
    // !!!
    // .AddXpoServices()
    // !!!
    ;
    services.AddControllers().AddOData((options, serviceProvider) => {
        options
            .AddRouteComponents("api/odata", new EdmModelBuilder(serviceProvider).GetEdmModel())
            .EnableQueryFeatures(100);
    });
    services.AddSwaggerGen(c => {
        c.EnableAnnotations();
        c.SwaggerDoc("v1", new OpenApiInfo {
            Title = "MySolution API",
            Version = "v1",
            Description = @"Use AddXafWebApi(Configuration, options) in the MySolution.Blazor.Server\Startup.cs file to make Business Objects available in the Web API."
        });
    });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if(env.IsDevelopment()) {
        // ...
        app.UseSwagger();
        app.UseSwaggerUI(c => {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "MySolution WebApi v1");
        });
    }
    // ...
}

#Configure Authentication Settings (Optional)

The Web API supports all standard ASP.NET Core authentication techniques. See the following topic for more information: Authentication in Web API projects.

#Create Endpoints and Test the Web API

You can now create endpoints and test the Web API.

#Add Web API Service: Additional Modules

You can enable additional Web API Service modules in an existing application. For instructions, please refer to the topic that describes the required module:

A number of modules are available to you right away, without the need for manual registration:

Note

Additional modules listed above ship only as part of the DevExpress Universal Subscription.

See Also