Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
966 views
in Technique[技术] by (71.8m points)

asp.net web api - Error if I invoke the microservice through the gateway with Ocelot 16.0

I am carrying out a project with apigateway and microservice Employees with visual studio 2019 with net.core 3.1

My configuration.json is:

 "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/employees/{everything}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "provadb",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/api/employees/{everything}",
      "UpstreamHttpMethod": [ "POST", "PUT", "GET" ]
    }

In controllers:

public class EmployeesController : ControllerBase
    {
        private readonly ProvaDBContext _context;

        public EmployeesController(ProvaDBContext context)
        {
            _context = context;
        }

        // GET: api/Employees
        [HttpGet]
        public async Task<ActionResult<IEnumerable<Employees>>> GetEmployees()
        {
            return await _context.Employees.ToListAsync();
        }

docker-compose.override.yml

version: '3.4'

services:
  shapesapigateway:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://+:80
    ports:
      - "7000:80"
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
  
  provadb:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://+:80
    ports:
       - "7004:80"
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

networks:
    app-net:
        driver: bridge

but if write in browser:

localhost:7004/api/Employees

results is:

[
    {
        "id": 1,
        "firstName": "Pranaya",
        "lastName": "Rout",
        "gender": "Male",
        "salary": 60000
    },
    {
        "id": 2,
        "firstName": "Anurag",
        "lastName": "Mohanty",
        "gender": "Male",
        "salary": 45000
    },
    {
        "id": 3,
        "firstName": "Preety",
        "lastName": "Tiwari",
        "gender": "Female",
        "salary": 45000
    },
    {
        "id": 4,
        "firstName": "Sambit",
        "lastName": "Mohanty",
        "gender": "Male",
        "salary": 70000
    },
    {
        "id": 5,
        "firstName": "Shushanta",
        "lastName": "Jena",
        "gender": "Male",
        "salary": 45000
    },
    {
        "id": 6,
        "firstName": "Priyanka",
        "lastName": "Dewangan",
        "gender": "Female",
        "salary": 30000
    },
    {
        "id": 7,
        "firstName": "Sandeep",
        "lastName": "Kiran",
        "gender": "Male",
        "salary": 45000
    },
    {
        "id": 8,
        "firstName": "Shudhansshu",
        "lastName": "Nayak",
        "gender": "Male",
        "salary": 30000
    },
    {
        "id": 9,
        "firstName": "Hina",
        "lastName": "Sharma",
        "gender": "Female",
        "salary": 35000
    },
    {
        "id": 10,
        "firstName": "Preetiranjan",
        "lastName": "Sahoo",
        "gender": "Male",
        "salary": 80000
    },
    {
        "id": 12,
        "firstName": "PIO",
        "lastName": "NONO",
        "gender": "M",
        "salary": 1234
    }
]

but if I write in the browser:

localhost:7000/api/Employees

 *'/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.10/System.Runtime.Intrinsics.dll' è stato caricato. Caricamento dei simboli ignorato. Il modulo è ottimizzato e l'opzione del debugger 'Solo codice utente' è abilitata.
    Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 GET http://localhost:7000/api/Employees  
    info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
          Request starting HTTP/1.1 GET http://localhost:7000/api/Employees  
    dbug: Ocelot.Errors.Middleware.ExceptionHandlerMiddleware[0]
          requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: ocelot pipeline started
    Ocelot.Errors.Middleware.ExceptionHandlerMiddleware: Debug: requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: ocelot pipeline started
    dbug: Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware[0]
          requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: Upstream url path is /api/Employees
    Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware: Debug: requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: Upstream url path is /api/Employees
    warn: Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware[0]
          requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /api/Employees, verb: GET.
    Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware: Warning: requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /api/Employees, verb: GET.
    warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
    Ocelot.Responder.Middleware.ResponderMiddleware: Warning: requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /api/Employees, verb: GET. errors found in ResponderMiddleware. Setting error response for request path:/api/Employees, request method: GET
          requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /api/Employees, verb: GET. errors found in ResponderMiddleware. Setting error response for request path:/api/Employees, request method: GET
    dbug: Ocelot.Errors.Middleware.ExceptionHandlerMiddleware[0]
          requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: ocelot pipeline finished
    Ocelot.Errors.Middleware.ExceptionHandlerMiddleware: Debug: requestId: 0HM5DM6ULMR8I:00000002, previousRequestId: no previous request id, message: ocelot pipeline finished
    info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
          Request finished in 23.4902ms 404* 

I can't understand where I'm wrong!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...