【问题标题】:What is real web-url for mORMot web-service?mORMot 网络服务的真实网址是什么?
【发布时间】:2015-09-11 18:27:59
【问题描述】:

请帮助理解下面的web-service的路由和web-url。

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;

我尝试调用 follow web-urls:

但每次我得到:

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

Bad request

我哪里错了?

【问题讨论】:

  • 您的工作不是通过调用HTTPServer.RootRedirectToURI('api/default')RESTServer.RootRedirectGet := 'api/default'; 来设置服务器ROOT 重定向。我没有直接使用其他服务器的经验,但我看到其他人使用这种方法:stackoverflow.com/questions/32481966/…
  • 我的例子是使用 MVC,现在我只需要纯 Web 服务...

标签: delphi mormot


【解决方案1】:

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

  • http://localhost:8092/root/AirportService/GetAirportDefinition?AirPortID=1
  • http://localhost:8092/root/AirportService.GetAirportDefinition?AirPortID=1

【讨论】:

    猜你喜欢
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2020-09-22
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多