2015-09-11 39 views
1

請幫助理解下面的web服務的路由和web-url。什麼是mORMot網絡服務的真實網頁?

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; 

我打電話遵循網頁的URL:

但每次我得到:

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

Bad request

我在哪裏錯了?

+0

不是你的工作設置服務器重定向ROOT(」 api/default')'和'RESTServer.RootRedirectGet:='api/default';'。我沒有與其他服務器的直接經驗,但我看到其他人使用這種方法:http://stackoverflow.com/questions/32481966/delphi-whats-wrong-with-rest-api-based-on-mormot – SilverWarior

+0

我舉例被使用MVC,現在我只需要純Web服務... – SpanishBoy

回答

0

A是錯誤的,真的下面的網址需要工作原理:通過調用`HTTPServer.RootRedirectToURI

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