1

请帮助了解以下网络服务的路由和网络网址。

type
  TAirportService = class(TInterfacedObject, IAirportService)
  public
    procedure GetAirportDefinition(const AirPortID: integer; out Definition: TDTOAirportDefinition);
  end;

procedure TAirportService.GetAirportDefinition(const AirPortID: integer;
  out Definition: TDTOAirportDefinition);
begin
  // create an object from static data
  // (real application may use database and complex code to retrieve the values)
  with Definition.Airport.Add do begin
    Location := 'LAX';
    Terminal := TRawUTF8DynArrayFrom(['terminalA', 'terminalB', 'terminalC']);
    Gate := TRawUTF8DynArrayFrom(['gate1', 'gate2', 'gate3', 'gate4', 'gate5']);
    BHS := 'Siemens';
    DCS := 'Altiea';
  end;
  with Definition.Airline.Add do begin
    CX := TRawUTF8DynArrayFrom(['B777', 'B737', 'A380', 'A320']);
    QR := TRawUTF8DynArrayFrom(['A319', 'A380', 'B787']);
    ET := '380';
    SQ := 'A320';
  end;
  Definition.GroundHandler := TRawUTF8DynArrayFrom(['Swissport','SATS','Wings','TollData']);
end;

procedure StartWebService();
var
  aModel: TSQLModel;
  aDB: TSQLRestServer;
  aServer: TSQLHttpServer;
begin
  // set the logs level to only important events (reduce .log size)
  TSQLLog.Family.Level := LOG_STACKTRACE+[sllInfo,sllServer];
  // initialize the ORM data model
  aModel := TSQLModel.Create([]);
  try
    // create a fast in-memory ORM server
    aDB := TSQLRestServerFullMemory.Create(aModel,'test.json',false,false);
    try
      // register our TAirportServer implementation
//      aDB.ServiceRegister(TServiceCalculator,[TypeInfo(ICalculatorXML)],sicShared);
      aDB.ServiceRegister(TAirportService,[TypeInfo(IAirportService)],sicShared);
      // launch the HTTP server
      aServer := TSQLHttpServer.Create('8092', [aDB], '+', useHttpApiRegisteringURI);
      try
        aServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
        writeln('Background server is running'#10);
        write('Press [Enter] to close the server.');
        ConsoleWaitForEnterKey;
      finally
        aServer.Free;
      end;
    finally
      aDB.Free;
    end;
  finally
    aModel.Free;
  end;
end;

我尝试调用以下网址:

但每次我得到:

{ "errorCode":400, "errorText":"Bad Request" }

或者Bad request

我哪里错了?

4

1 回答 1

1

A 错了,下面的 url 真的可以根据需要工作:

  • http://localhost:8092/root/AirportService/GetAirportDefinition?AirPortID=1
  • http://localhost:8092/root/AirportService.GetAirportDefinition?AirPortID=1
于 2015-09-14T07:22:50.337 回答