#1 2014-09-10 16:35:09

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Interface Services without Parameters

Hi Arnaud,

It currently seems impossible to support functions in interfaces that do not require parameters?

for instance

interface IServerInfo
  function IsRunning: Boolean;
end;

will return an error if the caller does a /server/isRunning

However, if I add any parameters to the URL, it works... e.g. /server/isRunning?random=13348

I believe this is due to checks for parameter list <> nil

Could there be an exception to this check for occurrences where the function is not expecting any parameters?

Offline

#2 2014-09-10 19:02:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: Interface Services without Parameters

Weird.
The regression tests contains signature like this:

  ITestUser = interface(IInvokable)
    ['{EABB42BF-FD08-444A-BF9C-6B73FA4C4788}']
    function GetContextSessionID: integer;
    function GetContextSessionUser: integer;
    function GetContextSessionGroup: integer;
  end;

Which kind of client are you using?
What is your server configuration (routing, service options, etc...)?
Have you simple code to reproduce the issue?

Offline

#3 2014-09-11 04:15:16

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: Interface Services without Parameters

Hi Arnaud,

I'm just calling it from the browser via http://localhost:8080/admin/AdminServer/isRunning

Very simple to reproduce:

  IAdminServer = interface(IInvokable)
    ['{E3097205-9424-427E-B6B4-D61E044CC6C3}']
    function IsRunning: Boolean;
  end;

  TAdminServer = class(TInterfacedObject, IAdminServer)
  public
    function IsRunning: Boolean;
  end;

  function TAdminServer.IsRunning: Boolean;
  begin
    Result := True;
  end;

// ---- snip ----

  AdminModel := TSQLModel.Create([TSQLUser], 'admin');
  AdminDB := TSQLRestServerDB.Create(AdminModel, 'admin.db', False);
  AdminServer := TSQLHttpServer.Create('8080', [AdminDB], '+', useHttpApiRegisteringURI, 32, secNone);
  AdminServer.AccessControlAllowOrigin := '*';
  AdminDB.ServiceRegister(TAdminServer, [TypeInfo(IAdminServer)], sicShared);

Code fails in mORMot.pas line 27791 because Par is nil, and the if statement is trying to perform character matching.

If I amend the line to

    if (Par<>nil) and ((Par^='[') or IdemPChar(Par,'%5B')) then

it still fails at line 27047 of mORMot.pas because as long as the parameter list is nil, it will exit with an error.

Offline

#4 2014-09-11 07:15:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: Interface Services without Parameters

Interface based services were not meant to be used as such, directly from the browser, in fact!
You have much more ideas than us!
smile

OK - now interface-based services allow to be called without any input parameter (i.e. no incoming HTTP body, nor value encoded at URI level).
In this case, default values will be set for the method call.
See http://synopse.info/fossil/info/54f5c7839c

Offline

#5 2014-09-11 18:05:30

cheemeng
Member
From: Malaysia
Registered: 2011-08-09
Posts: 61

Re: Interface Services without Parameters

Thanks Arnaud!

Offline

Board footer

Powered by FluxBB