ASP.NET Core Integration

ASP.NET Core integration

Aspose.Medical.Dicom.Web.AspNetCore is a separate NuGet package for hosting Aspose.Medical DICOMweb applications in ASP.NET Core. It registers application services with dependency injection, maps a DICOMweb service root to endpoints, writes HTTP responses, and connects notification sessions to WebSockets. The core Aspose.Medical package supplies the DICOM data model, transaction dispatch, standard handlers, provider contracts, and client APIs.

Requirements

  • Development: the .NET 10 SDK and a project targeting net10.0.
  • Hosting: ASP.NET Core 10 (Microsoft.AspNetCore.App). Framework-dependent deployments require the ASP.NET Core runtime on the server; self-contained deployments include the required runtime components. The .NET runtime alone is insufficient for this host.
  • Project type: an ASP.NET Core application using Microsoft.NET.Sdk.Web references the ASP.NET Core shared framework automatically. The bridge declares its shared-framework requirement in the package; do not install Microsoft.AspNetCore.App as a NuGet package. See Microsoft’s shared-framework guidance.

Use an operating system and architecture supported by .NET 10, as described in the main requirements guide. The host supplies TLS, authentication, authorization, CORS, request limits, and any application storage or workflow services used by its handlers.

Installation

Create an ASP.NET Core application and install the bridge package:

dotnet new web -n DicomWebServer --framework net10.0
cd DicomWebServer
dotnet add package Aspose.Medical.Dicom.Web.AspNetCore

For an existing ASP.NET Core project, run only the dotnet add package command in its project directory. In Visual Studio, open Tools > NuGet Package Manager > Manage NuGet Packages for Solution, search for Aspose.Medical.Dicom.Web.AspNetCore, and install it into the server project.

Core package dependency

NuGet automatically restores Aspose.Medical as a separate dependency. Each bridge release declares an exact compatible core version; a constraint such as [26.10.0] requires core version 26.10.0. Check the selected bridge version’s Dependencies on its NuGet page when upgrading, and align any direct Aspose.Medical reference in your project with that requirement.

The bridge package contains its own assembly and XML API documentation. It does not embed the core assembly or core source code. Publish and deploy the application with both restored packages; copying only Aspose.Medical.Dicom.Web.AspNetCore.dll is insufficient. The DICOMweb APIs keep the Aspose.Medical.Dicom.Web namespace, including the ASP.NET Core registration and endpoint extensions.

Evaluation and licensing

Installing the bridge package does not activate an Aspose.Medical license. DICOM processing through the bridge uses the core library’s licensing state and remains subject to its evaluation and feature-specific restrictions. See the main licensing guide for license loading and evaluation limits, or request a temporary license for evaluation.

Apply your Aspose.Medical license once during application startup, before accepting requests that process DICOM data. For a license file, add the following before app.RunAsync() in Program.cs:

Aspose.Medical.License license = new();
license.SetLicense("Aspose.Medical.lic");

The bridge has no separate license activation API. If using metered licensing, call SetMeteredKey on an Aspose.Medical.Metered instance during startup instead of loading a license file. Do not initialize or reset licensing for each HTTP request.

Complete minimal application: standard handler

This Program.cs is a working read-only MWL-RS server with an intentionally empty in-memory worklist. It demonstrates the complete provider contract and responds to search requests without installing persistence:

AddDicomWeb() registers a scoped DICOMweb application and returns DicomWebAspNetCoreBuilder. Its overload accepts an Action<DicomWebAspNetCoreOptions>. ConfigureApplication(Action<DicomWebApplicationBuilder>) configures the application built for each request scope.

Microsoft.AspNetCore.Builder.WebApplicationBuilder builder =
    Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);
Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddScoped<
    Aspose.Medical.Dicom.Web.Providers.IDicomWebModalityWorklistProvider,
    EmptyModalityWorklist>(builder.Services);
Aspose.Medical.Dicom.Web.DicomWebServiceCollectionExtensions.AddDicomWeb(builder.Services)
    .AddStandardModalityWorklistService();

Microsoft.AspNetCore.Builder.WebApplication app = builder.Build();
Aspose.Medical.Dicom.Web.DicomWebEndpointRouteBuilderExtensions.MapDicomWeb(app, "/dicomweb");
await app.RunAsync();

public sealed class EmptyModalityWorklist : Aspose.Medical.Dicom.Web.Providers.IDicomWebModalityWorklistProvider
{
    public async System.Collections.Generic.IAsyncEnumerable<Aspose.Medical.Dicom.Dataset> FindCandidatesAsync(
        Aspose.Medical.Dicom.Web.Providers.DicomWebSearchContext search,
        [System.Runtime.CompilerServices.EnumeratorCancellation] System.Threading.CancellationToken cancellationToken = default)
    {
        cancellationToken.ThrowIfCancellationRequested();
        await System.Threading.Tasks.Task.CompletedTask;
        yield break;
    }
}

For a real worklist, query the backend in stable order from FindCandidatesAsync; the library performs final matching and projection. The equivalent hosting-neutral setup is DicomWebApplication.CreateBuilder().AddStandardModalityWorklistService(new EmptyModalityWorklist()).Build().

To expose Studies instead, use the complete InMemoryStudies and NoRenderedRepresentations classes in standard services and replace the worklist registrations above with:

Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton<
    Aspose.Medical.Dicom.Web.Providers.IDicomWebStudiesProvider,
    InMemoryStudies>(builder.Services);
Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton<
    Aspose.Medical.Dicom.Web.Providers.IDicomWebRepresentationProvider,
    NoRenderedRepresentations>(builder.Services);
Aspose.Medical.Dicom.Web.DicomWebServiceCollectionExtensions.AddDicomWeb(builder.Services)
    .AddStandardStudiesService();

The singleton in-memory archive survives request scopes for the lifetime of this demo process. Use application-managed persistence and an appropriate DI lifetime in a real service.

Complete custom handler for the same transaction

Replace the provider registration and standard registration above with this DI registration, and use EmptyWorklistHandler from custom handlers:

Aspose.Medical.Dicom.Web.DicomWebServiceCollectionExtensions.AddDicomWeb(builder.Services)
    .AddHandler<Aspose.Medical.Dicom.Web.Transactions.SearchModalityScheduledProcedureSteps,
                EmptyWorklistHandler>();

AddHandler<TTransaction,THandler> and AddHandlerFactory<TTransaction,TFactory> accept a ServiceLifetime (default Scoped); AddOpenRequestBehavior<TFactory> registers a Communication pipeline behavior factory. ConfigureApplication can additionally enable/disable services or add hosting-neutral behaviors. A scoped DicomWebApplication is built from registration callbacks using the request scope’s services. Use a handler factory when a new handler instance is required for each dispatch. A directly registered DI handler is resolved when its application scope is constructed. A later registration for the same transaction replaces the earlier one; register the standard service first when replacing only one of its transactions. Standard provider methods are also resolved from that scope.

Endpoint mapping and transport

MapDicomWeb(pattern) resolves the scoped application from request services. MapDicomWeb(pattern, application) uses the explicitly built immutable application. Both map the root and all resource paths beneath a static service-root path, such as /dicomweb, and return an IEndpointConventionBuilder so endpoint conventions can be applied to the group. The relative DICOMweb resource path excludes the service root. The base URI used for result links includes the request scheme, host, path base, and mapped root; configure ASP.NET Core forwarded headers in the host before relying on proxy-supplied origin values. The route group and host’s middleware supply ordinary ASP.NET Core endpoint features.

The adapter parses ordered query parameters and headers, wraps HttpRequest.BodyReader in a DicomWebPayloadReader, resolves an optional IAsyncBulkDataLoader from request services, passes RequestAborted to ProcessAsync, and writes status, response headers, Content-Type, optional Content-Length, and content to HttpResponse.BodyWriter. The adapter disposes its payload reader without completing the host-owned request pipe. A malformed query string receives HTTP 400. DicomWebResponse content writing may stream after handler completion, so scoped providers and request services must remain valid for the entire response. Exceptions not converted into an application response follow the host’s exception handling pipeline.

DicomWebAspNetCoreOptions.NotificationCloseTimeout defaults to 5 seconds and must be positive. It limits waiting for the peer to complete the WebSocket close handshake after server notification enumeration finishes. It does not configure ASP.NET Core request-body, WebSocket, authentication, or response timeouts.

Notification WebSockets and host policy

When UPS notifications are registered, call the host’s WebSocket middleware and map the DICOMweb endpoints in the usual ASP.NET Core pipeline. A DicomWebNotificationSession supplies handshake headers and ordered event-report datasets. The adapter accepts the WebSocket, writes each dataset as one DICOM JSON text message, and initiates a close handshake after the sequence ends. Request abortion cancels enumeration and transmission. The host must provide authenticated requester identity and appropriate authorization; it also owns CORS, TLS, forwarded headers, upload limits, and WebSocket policy. CORS does not restrict WebSocket origins; configure the host’s WebSocket origin policy separately. IDicomWebSubscriptionProvider owns subscription persistence and notification queues.

Place the middleware before the DICOMweb endpoint when using notification connections:

Microsoft.AspNetCore.Builder.WebSocketMiddlewareExtensions.UseWebSockets(app);
Aspose.Medical.Dicom.Web.DicomWebEndpointRouteBuilderExtensions.MapDicomWeb(app, "/dicomweb");

An explicitly built application can be mapped without AddDicomWeb:

Aspose.Medical.Dicom.Web.DicomWebApplication application =
    Aspose.Medical.Dicom.Web.DicomWebApplication.CreateBuilder()
        .AddStandardModalityWorklistService(new EmptyModalityWorklist())
        .Build();
Aspose.Medical.Dicom.Web.DicomWebEndpointRouteBuilderExtensions.MapDicomWeb(app, "/dicomweb", application);

In that form the caller owns the application and its provider lifetimes. Use the DI form when request-scoped dependencies are required.