Service Connection Refused at Wrong Host

Hello, i am running my services and Consul as localy. like that:

basically appsetting.json file of any service:

  "ServiceSettings": {
    "ServiceName": "My-Service-Name",
    "ServiceHost": "127.0.0.1",
    "ServicePort": 8001,
    "ServiceDiscoveryAddress": "http://127.0.0.1:8500"
  }

Registering, connecting successful to my gateway adress (127.0.0.1:8000) and consul (127.0.0.1:8500). After that when i make a request i get “ConnectionToDownstreamServiceError Message: Error connecting to downstream service, exception: System.Net.Http.HttpRequestException: Connection refused ({device-name}:8001)”.

why the hostname returns as {device-name}:8001? I think problem is causes by.

Hi @ramalt,

How is your service getting registered to Consul? It seems like whatever is registering the service is not interpolating the {device-name} variable prior to issuing the API call.

@ramalt Did you manage to resolve this?
I’m using .NET 6.0 Consul Agent Service Registration method. Facing similar issue where the address is configured as localhost but the routing happens with the node name.

Error: 400 (Bad Request) status code of request URI: http://dotnetfsd:55031/api/authentication/login

node name in consul: dotnetfsd

Service Registry Extension for Consul
-----------------------------------------------------

public static IApplicationBuilder UseConsul(this IApplicationBuilder app, IConfiguration configuration)
{
    var consulClient = app.ApplicationServices.GetRequiredService<IConsulClient>();
    var lifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
    string hostname = configuration.GetSection("ConsulSettings:ServiceHost").Value;
    int port = int.Parse(configuration.GetSection("ConsulSettings:ServicePort").Value);
    foreach (IConfigurationSection service in configuration.GetSection("ConsulSettings:services").GetChildren())
    {
        var serviceRegistration = new AgentServiceRegistration()
        {
            ID = service.Value,
            Name = service.Value,
            Address = hostname,
            Port = port
        };
        consulClient.Agent.ServiceDeregister(serviceRegistration.ID).ConfigureAwait(true);
        consulClient.Agent.ServiceRegister(serviceRegistration).ConfigureAwait(true);
    }
    return app;
}

AppSettings.json
------------------------
"ConsulSettings": {
  "services": [ "AuthenticationService", "CredentialManagerService" ],
  "ServiceHost": "localhost",
  "ServicePort": "55031",
  "ConsulAddress": "http://localhost:8500"
}