Skip to content

feat: Add configurable WCF binding timeouts for ONVIF clients#54

Open
TWhidden wants to merge 5 commits intoJazea:masterfrom
TWhidden:master
Open

feat: Add configurable WCF binding timeouts for ONVIF clients#54
TWhidden wants to merge 5 commits intoJazea:masterfrom
TWhidden:master

Conversation

@TWhidden
Copy link
Copy Markdown

Description

Purpose

Add support for configurable WCF binding timeouts in the ONVIF client factory to enable faster failure detection and better control over network operation timeouts.

Problem

WCF bindings use 1-minute default timeouts for connection operations, which can cause long delays when cameras are unreachable or unresponsive. Applications need the ability to override these timeouts for faster failure handling.

Solution

Introduced OnvifBindingTimeoutConfiguration class with four nullable timeout properties:

  • OpenTimeout - Connection establishment timeout
  • SendTimeout - Request transmission timeout
  • ReceiveTimeout - Response reception timeout
  • CloseTimeout - Connection closure timeout

Configuration is opt-in via OnvifClientFactory.BindingTimeoutConfig static property. Null values preserve WCF defaults, ensuring backward compatibility.

Changes

  • Added OnvifBindingTimeoutConfiguration.cs - New configuration class with nullable timeout properties
  • Modified OnvifClientFactory.cs - Added BindingTimeoutConfig static property and timeout application logic
  • Timeouts only applied when explicitly configured; unset values use WCF defaults

Backward Compatibility

✅ Fully backward compatible - library behavior unchanged unless BindingTimeoutConfig is explicitly set

Usage Example

Override all default WCF timeouts:

// Override default WCF timeouts
OnvifClientFactory.BindingTimeoutConfig = new OnvifBindingTimeoutConfiguration
{
    OpenTimeout = TimeSpan.FromSeconds(8),
    SendTimeout = TimeSpan.FromSeconds(8),
    ReceiveTimeout = TimeSpan.FromSeconds(8),
    CloseTimeout = TimeSpan.FromSeconds(8)
};

// Clients created after this will use the configured timeouts
var device = await OnvifClientFactory.CreateDeviceClientAsync(host, username, password);

// Or set individual timeouts:
OnvifClientFactory.BindingTimeoutConfig = new OnvifBindingTimeoutConfiguration
{
    OpenTimeout = TimeSpan.FromSeconds(8)  // Only override OpenTimeout
    // SendTimeout, ReceiveTimeout, CloseTimeout remain at WCF defaults
};

Enabled #nullable for specific class files only, as enabling it in the .csproj would generate over 1,000 warnings due to generated code requiring significant refactoring to support nullable annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant