microsoft / microsoft/aspire

Service Discovery doesn't resolve http endpoints correctly

Open
#8,559 0 comments 0 reactions 0 assignees View on GitHub
area-service-discovery
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I am attempting to use Microsoft.Extensions.ServiceDiscovery without an Aspire app host or service defaults. The NuGet package linked here for the source repo, so I assume this is the correct place to post this issue.

I have a Refit client that I've configured to use Service Discovery:
```c#
services.AddRefitClient()
.AddServiceDiscovery()
.ConfigureHttpClient(c =>
{
c.BaseAddress = new Uri("https+http://my-api");
});
```

This service is running locally HTTP only on port 5100 (as a Python Flask API, if that matters). I configured my appsettings json as such:
```json
"Services": {
"my-api": {
"http": [
"localhost:5100"
]
}
}
```

I want to use HTTPS when running in the cloud, so I used the `https+http` scheme when configuring the HttpClient, but I want to use HTTP locally, hence my JSON config. This invokes service discovery and translates `https+http://my-api` to `localhost:5100`, but the problem is that it is using `https` instead of `http`. This causes errors because it's not a valid TLS endpoint.

I would have expected service discovery to look in my config for `Services:my-api:https`, not found that, then looked for `Services:my-api:http`, found that value, and used `http://localhost:5100` as the resolved URL.

Perhaps I'm using the API/configuration wrong... is there a way to prevent it from trying https locally without i.e. making the base address an IConfiguration value? I've tried disallowing the https scheme when the environment is development, but then it errors because the service discovery url includes https.

### Expected Behavior

Service Discovery should have resolved the URL to `http://localhost:5100` as that is what was configured.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

Microsoft.Extensions.ServiceDiscovery version 9.1.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.