#1 2024-08-21 08:59:38

anouri
Member
Registered: 2024-02-11
Posts: 47

Serive server is nil

Hi,
I create custom server
TMyRest = class(TRestServerFullMemory)
and register service
aServer.ServiceRegister(InvoiceService, [TypeInfo(IInvoiceService)],'1');

but in serivce methods self.server (TRestServer) is nil!

Last edited by anouri (2024-08-21 09:11:13)

Offline

#2 2024-08-21 09:44:26

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

Re: Serive server is nil

How is TInvoiceService class defined?

Online

#3 2024-08-21 09:57:33

anouri
Member
Registered: 2024-02-11
Posts: 47

Re: Serive server is nil

unit Service.Invoice ;

TInvoiceService = class(TInjectableObjectRest, IInvoiceService)
public
constructor Create; overload;
function GetInvoiceList(const DateFr,DateTo: string): RawJson;


function TInvoiceService.GetInvoiceList(const DateFr,DateTo: string): RawJson;
begin
--   self.server is nil here
end;

constructor TInvoiceService.Create;
begin
  inherited Create;
end;

Last edited by anouri (2024-08-21 10:05:04)

Offline

#4 2024-08-21 13:41:02

anouri
Member
Registered: 2024-02-11
Posts: 47

Re: Serive server is nil

I can't find anything wrong. Any suggestions?

Offline

#5 2024-08-21 14:09:48

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

Re: Serive server is nil

I guess because you created your own sicShared instance with your own TInvoiceService.Create without setting the property.
Auto-fill of the Server property is only if the framework make it.
If you make wrong initialization, it is... working wrong.

My guess is that you should call CreateWithResolverAndRest() as constructor, with the proper parameters, or just don't create your instance, but let the framework do it as sicShared, by providing a class and not an instance.

Online

#6 2024-08-21 15:18:35

JD
Member
Registered: 2015-08-20
Posts: 118

Re: Serive server is nil

anouri wrote:

I can't find anything wrong. Any suggestions?

Can you try this:

aServer.ServiceRegister(TInvoiceService, [TypeInfo(IInvoiceService)], '1');     // <----   replacing InvoiceService with TInvoiceService

JD

Last edited by JD (2024-08-21 15:19:38)

Offline

#7 2024-08-22 06:12:55

anouri
Member
Registered: 2024-02-11
Posts: 47

Re: Serive server is nil

[dcc32 Error] View.Server.pas(109): E2250 There is no overloaded version of 'ServiceRegister' that can be called with these arguments

Offline

#8 2024-08-22 06:50:37

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

Re: Serive server is nil

You could have searched a little bit:

aServer.ServiceRegister(TInvoiceService, sicShared, [TypeInfo(IInvoiceService)], '1');     // <----   replacing InvoiceService with TInvoiceService

Online

#9 2024-08-22 08:21:37

anouri
Member
Registered: 2024-02-11
Posts: 47

Re: Serive server is nil

Thank you so much. this one worked: smile
aServer.ServiceRegister(TInvoiceService, [TypeInfo(IInvoiceService)], sicShared, '1');

Last edited by anouri (2024-08-22 08:22:28)

Offline

Board footer

Powered by FluxBB