DevInstance.WebServiceToolkit 10.3.2

dotnet add package DevInstance.WebServiceToolkit --version 10.3.2
                    
NuGet\Install-Package DevInstance.WebServiceToolkit -Version 10.3.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DevInstance.WebServiceToolkit" Version="10.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DevInstance.WebServiceToolkit" Version="10.3.2" />
                    
Directory.Packages.props
<PackageReference Include="DevInstance.WebServiceToolkit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DevInstance.WebServiceToolkit --version 10.3.2
                    
#r "nuget: DevInstance.WebServiceToolkit, 10.3.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DevInstance.WebServiceToolkit@10.3.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DevInstance.WebServiceToolkit&version=10.3.2
                    
Install as a Cake Addin
#tool nuget:?package=DevInstance.WebServiceToolkit&version=10.3.2
                    
Install as a Cake Tool

DevInstance.WebServiceToolkit

ASP.NET Core utilities for web service development including query model binding, exception handling, and service registration.

Installation

dotnet add package DevInstance.WebServiceToolkit

This package includes DevInstance.WebServiceToolkit.Common and DevInstance.WebServiceToolkit.Database as dependencies.

Features

  • Query Model Binding - Automatic binding of query string parameters to strongly-typed POCOs
  • Exception Handling - Standardized HTTP exception types with automatic response mapping
  • Service Registration - Attribute-based automatic dependency injection

Quick Start

1. Configure Services

using DevInstance.WebServiceToolkit.Http.Query;
using DevInstance.WebServiceToolkit.Tools;

var builder = WebApplication.CreateBuilder(args);

// Add query model binding support
builder.Services.AddControllers()
    .AddWebServiceToolkitQuery();

// Auto-register services marked with [WebService]
builder.Services.AddServerWebServices();

2. Query Model Binding

Define query models with the [QueryModel] attribute:

using DevInstance.WebServiceToolkit.Http.Query;
using System.ComponentModel;

[QueryModel]
public class ProductQuery
{
    [DefaultValue(0)]
    public int Page { get; set; }

    [DefaultValue(20)]
    public int PageSize { get; set; }

    public string? Search { get; set; }

    [QueryName("sort")]
    public string? SortBy { get; set; }
}

Use in controllers - binding happens automatically:

[HttpGet]
public ActionResult<ProductList> GetProducts(ProductQuery query)
{
    // query is populated from ?page=0&pageSize=20&search=widget&sort=name
}

3. Exception Handling

Use HandleWebRequestAsync to automatically convert exceptions to HTTP responses:

using DevInstance.WebServiceToolkit.Controllers;
using DevInstance.WebServiceToolkit.Exceptions;

[HttpGet("{id}")]
public Task<ActionResult<Product>> GetProduct(string id)
{
    return this.HandleWebRequestAsync<Product>(async () =>
    {
        var product = await _productService.GetByIdAsync(id);
        if (product == null)
            throw new RecordNotFoundException(id);  // Returns 404
        return Ok(product);
    });
}

Exception to HTTP Status Mapping:

Exception HTTP Status errorType
BadRequestException 400 Bad Request Validation
UnauthorizedException 401 Unauthorized General
ForbiddenException 403 Forbidden General
RecordNotFoundException 404 Not Found General
RecordConflictException 409 Conflict General
UnprocessableEntityException 422 Unprocessable Entity Validation
Any other WebServiceException its StatusCode General
Other exceptions 500 — message hidden outside Development, stack trace never sent Exception

Every error response carries a WebServiceError JSON body:

{ "errorType": 3, "message": "Name is required", "propertyName": "Name" }

It is wire-compatible with DevInstance.BlazorToolkit's ServiceActionError, so Blazor clients using HttpApiContext read the message and property name directly. Derive your own domain exceptions from WebServiceException (or a concrete exception) to control their status code.

To give [ApiController] model-validation failures the same body, register:

builder.Services.AddControllers()
    .AddWebServiceToolkitErrors();

A global IExceptionHandler can produce the same body for exceptions thrown outside HandleWebRequestAsync via ControllerUtils.ToWebServiceError(exception).

4. Service Registration

Mark services for automatic DI registration:

using DevInstance.WebServiceToolkit.Tools;

public interface IProductService
{
    Task<Product?> GetByIdAsync(string id);
}

[WebService]
public class ProductService : IProductService
{
    // Automatically registered as scoped service
}

// For testing, use WebServiceMock
[WebServiceMock]
public class MockProductService : IProductService
{
    // Register with AddServerWebServicesMocks()
}

Register services:

// Production
builder.Services.AddServerWebServices();

// Testing
builder.Services.AddServerWebServicesMocks();

API Reference

Query Model Binding

Type Description
QueryModelBinder Core query string parsing engine
QueryModelBindException Exception with per-field validation errors
QueryModelBinderProvider MVC model binder provider
QueryModelMvcBinder MVC model binder implementation
RegistrationExtensions DI registration extension methods

Exceptions

Type HTTP Status Description
BadRequestException 400 Invalid request data
UnauthorizedException 401 Authentication required
RecordNotFoundException 404 Resource not found
RecordConflictException 409 Resource conflict

Controllers

Type Description
ControllerUtils Extension methods for exception handling

Service Registration

Type Description
WebServiceAttribute Marks a class for automatic DI registration
WebServiceMockAttribute Marks a mock implementation for testing
ServiceConfigurationExtensions Assembly scanning and registration

See Also

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.3.2 83 9/26/2026
10.3.1 77 9/25/2026
10.3.0 75 9/25/2026
10.2.1 123 7/17/2026
10.2.0 126 3/26/2026
10.1.0 147 2/16/2026
10.0.4 143 1/28/2026
10.0.3 141 1/27/2026
10.0.2 131 1/27/2026
10.0.1 130 1/20/2026
10.0.0 302 11/10/2025
9.0.1 209 10/8/2025
9.0.0 161 10/3/2025
8.3.0 171 1/16/2025
8.2.0 168 1/16/2025
8.1.0 197 1/2/2025
8.0.0 191 12/18/2024
6.0.0 311 3/20/2025