I am trying to build a microservice architecture system using Ocelot as my API Gateway. I have had the current problem for about 2 weeks and have not been able to figure out why it is happening, so I am turing to the experts and hopefully you can help :).
The structure at the moment is as follows: I have an AccountAPI and an Ocelot API Gateway. I have added the route from the API Gateway to the AccountAPI according to the docs. When I run the project, I can call the AccountAPI directly, and it works fine. But when I call through the API Gateway, I get this error.
Error Code: ConnectionToDownstreamServiceError Message: Error connecting to downstream service, exception:
System.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it.
(localhost:5101)
Quite obviously, it is not even reaching the controller of the AccountAPI, so I can't even debug >.>
The fact that I can access the object without going through the gateway tells me it is not a network / firewall issue (I turned off all my firewalls just to test, and got the same result).
This is what is in my ocelot.json file (which should connect Ocelot to the AccountAPI)
{
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5111/"
},
"Routes": [
{
"DownstreamPathTemplate": "/Account/{url}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5101
}
],
"UpstreamPathTemplate": "/MeHealth/Account/{url}",
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ],
"Priority": 1
}
]
}
So if I call https:// localhost:5101/Account/1
I get my correct object returned. But with calling https:// localhost:5111/MeHalth/Account/1
I get the error. (I did also try http://
(for those who caught the scheme) and I get the same result as https)).
Other things to note: Both of these are deployed through the docker-compose with the following config:
services:
ocelotapigateway:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "5111:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
- ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro
accountapi:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "5101:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:C:\Users\ContainerUser\AppData\Roaming\Microsoft\UserSecrets:ro
- ${APPDATA}/ASP.NET/Https:C:\Users\ContainerUser\AppData\Roaming\ASP.NET\Https:ro
Any advice or help that you can give will be greatly appreciated. Please also let me know if you need extra information on something.