Closed kka-anand closed 6 years ago
@kka-anand can you set log level trace and paste the log here for failing requests. Also double check you are not using Ocelot 8.0.1 there was a bug in this.
Hi TomPallister,
You are correct. I have used Ocelot 8.0.1. Changed to Ocelot 8.0.2, now its working fine.
Thanks, Anand
Hi All,
I use Ocelot 8.0 and asp.net core 2.1. I have created two APIs Customers and Products with two different ports which are tested and working fine.
http://localhost:9001/api/customers http://localhost:9002/api/products
I've created an API gateway using Ocelot 8.0 in AP.Net CORE 2.1 and when I try to execute with another port (http://localhost:9000/api/products), it throws an error as shown below. I use IIS Express.
Here are the code snippets:
Program.cs
namespace APIGateway { public class Program { public static void Main(string[] args) { IWebHostBuilder builder = new WebHostBuilder(); builder.ConfigureServices(s => { s.AddSingleton(builder); }); builder.UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) // Replaces call to UseIISPlatformHandlerUrl() //.UseIISIntegration() .UseStartup()
.UseUrls("http://localhost:9000");
IWebHost host = builder.Build(); host.Run(); } } }
Startup.cs
namespace APIGateway { public class Startup { public Startup(IHostingEnvironment env) { var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.SetBasePath(env.ContentRootPath) //add configuration.json .AddJsonFile("configuration.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables();
Configuration = builder.Build(); }
//change public IConfigurationRoot Configuration { get; }
public void ConfigureServices(IServiceCollection services) { Action settings = (x) =>
{
x.WithMicrosoftLogging(log =>
{
log.AddConsole(LogLevel.Debug);
}).WithDictionaryHandle(); }; //services.AddOcelot(Configuration, settings); services.AddOcelot(Configuration); }
public async void Configure(IApplicationBuilder app, IHostingEnvironment env) { await app.UseOcelot(); } } }
Configuration.json { "ReRoutes": [ { "DownstreamPathTemplate": "/api/customers", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 9001 } ], "UpstreamPathTemplate": "/customers", "UpstreamHttpMethod": [ "Get" ] }, { "DownstreamPathTemplate": "/api/customers/{id}", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 9001 } ], "UpstreamPathTemplate": "/customers/{id}", "UpstreamHttpMethod": [ "Get" ] }, { "DownstreamPathTemplate": "/api/products", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 9002 } ], "UpstreamPathTemplate": "/api/products", "UpstreamHttpMethod": [ "Get" ] } ], "GlobalConfiguration": { "RequestIdKey": "OcRequestId", "AdministrationPath": "/administration" } }
launchSettings.cs { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:9000", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "APIGateway": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "https://localhost:5001;http://localhost:5000"
} } }
Thanks, Anand