#1 2022-09-12 10:21:23

Quorren
Member
Registered: 2016-10-03
Posts: 14

Access violation using ServiceRegister with client

Hi ab.

I am trying to use some services in DMZ and according to manual should be able to do this using  TSQLRestServer.ServiceRegister(aClient: TSQLRest;
I get AV error with call  "srv.ServiceRegister("

Here is my sample

climodel := ClientModule.GetModel;
RemoteClient := TSQLHttpClientWinHTTP.Create( 127.0.0.1, '333', climodel );
RemoteClient.OnAuthentificationFailed := OnAuthentificationFailed;

srv := TSQLRestServerRemoteDB.Create( RemoteClient );
srv.ServiceRegister(RemoteClient,[TypeInfo(ICABMeter)]);

What is the proper way to use this?

I see variable "aClient" has no use in implementation.

function TSQLRestServer.ServiceRegister(aClient: TSQLRest;
  const aInterfaces: array of PTypeInfo;
  aInstanceCreation: TServiceInstanceImplementation;
  const aContractExpected: RawUTF8): boolean;
begin
  result := False;
  if (self=nil) or (high(aInterfaces)<0) or (aClient=nil) then
    exit;
  result := (ServiceContainer as TServiceContainerServer).AddInterface(
    aInterfaces,aInstanceCreation,aContractExpected);
end;

Offline

#2 2022-09-12 11:01:31

xalo
Member
Registered: 2016-09-22
Posts: 32

Re: Access violation using ServiceRegister with client

I guess you have something misunderstood.
Is this on server side or client side ?

I think the documentation it's very very clear.

Offline

#3 2022-09-12 11:13:38

Quorren
Member
Registered: 2016-10-03
Posts: 14

Re: Access violation using ServiceRegister with client

xalo wrote:

I guess you have something misunderstood.
Is this on server side or client side ?

I think the documentation it's very very clear.

Maybe i did.
How to undestand this?


function ServiceRegister(aClient: TSQLRest; const aInterfaces: array of PTypeInfo; aInstanceCreation: TServiceInstanceImplementation=sicSingle; const aContractExpected: RawUTF8=''): boolean; overload; virtual;

Register a remote Service via its interface
- this overloaded method will register a remote Service, accessed via the supplied TSQLRest(ClientURI) instance: it can be available in the main TSQLRestServer.Services property, but execution will take place on a remote server - may be used e.g. for dedicated hosting of services (in a DMZ for instance)

Offline

#4 2022-09-12 12:43:48

xalo
Member
Registered: 2016-09-22
Posts: 32

Re: Access violation using ServiceRegister with client

Sorry, I don't understand you.

From client side you need to do something like that (extracted from sample 14):

...
Client := TSQLHttpClient.Create('localhost', PORT_NAME,Model);
Client.ServiceDefine([ICalculator],sicShared);

And service is prepared to be consumed from client:

...
if Client.Services['Calculator'].Get(I) then
    writeln(IntToStr(I.Add(a,b));

Offline

#5 2022-09-12 13:12:03

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

Re: Access violation using ServiceRegister with client

When you write

srv.ServiceRegister(RemoteClient,[TypeInfo(ICABMeter)]);

You are making a confusion between the REST client (RemoteClient) and the class instance implementing the ICABMeter service.

Offline

#6 2022-09-12 13:18:28

Quorren
Member
Registered: 2016-10-03
Posts: 14

Re: Access violation using ServiceRegister with client

I want to use part of internal services on public side.
So i have

InternalServer.ServiceDefine([IService1, IService2, IService3]);

I want to use it on external perimeter as

ExternalClient.Create()
ExternalServer.ServiceDefine( ExternalClient, [IService1] );

Of coarce the obvious way would be

ExternalClient.Create()
ExternalClient.ServiceDefine( [IService1] );

But this makes me responsible for creation and freeing client in every call or Having single client for my instance.
So i am trying to find a nice solution.

Since I did not find a way to use such a call in the examples, I started a thread.

Offline

Board footer

Powered by FluxBB