asp.net 微服务中 SOAP 服务的运行状况检查

问题描述 投票:0回答:1

我为 WCF SOAP 服务的 HealthCheck 设置了此设置,但由于某种原因,第二个委托中的代码未执行。如果我设置断点,它在调试中也不会被命中。

HealthCheckConfiguration healthCheckConfiguration = new ();
configureHealthChecks.Invoke(healthCheckConfiguration);
 
services
    .AddHealthChecks()
    .AddUrlGroup(
        (uriOptions) => uriOptions.UseHttpMethod(HttpMethod.Head),
        healthCheckConfiguration.Name,
        healthCheckConfiguration.FailureStatus,
        healthCheckConfiguration.Tags,
        healthCheckConfiguration.Timeout,
        (serviceProvider, httpClient) =>
        {
            var config = serviceProvider.GetRequiredService<IOptionsMonitor<TSettings>>();
            httpClient.BaseAddress = new($"{config.CurrentValue.Endpoint}?wsdl");
        });

第二个示例中的类似委托已命中并且工作正常,但我们希望将 HealthCheck 的请求从 GET 更改为 HEAD。

services
.AddHealthChecks()
    .AddUrlGroup(
        (services) =>
        {
            var config = services.GetRequiredService<IOptionsMonitor<TSettings>>();

            return new Uri($"{config.CurrentValue.Endpoint}?wsdl");
        },
        healthCheckConfiguration.Name,
        healthCheckConfiguration.FailureStatus,
        healthCheckConfiguration.Tags,
        healthCheckConfiguration.Timeout);
asp.net .net wcf soap health-check
1个回答
0
投票

尝试自定义检查:

public class ServiceCheck : IHealthCheck
{
    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
    {
        bool result = IsServiceOnline();
        if (result)
            return HealthCheckResult.Healthy();
        return HealthCheckResult.Unhealthy();
    }

    private bool IsServiceOnline()
    {
       //Your custom needs, such as HttpMethod.Head and other things
    }
}

public void ConfigureServices(IServiceCollection services)
{
    services.AddHealthChecks().AddCheck<ServiceCheck>($"{config.CurrentValue.Endpoint}?wsdl");
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.